Getting a Matrix of number of rows in R Programming - row() Function Last Updated : 20 Dec, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will discuss how to find the number of rows and columns in a matrix in R Programming Language. nrow() Function in Rnrow() function in R Language is used to get the row number of a matrix. Syntax: row(x, as.factor=FALSE) Parameters:x: matrixas.factor: a logical value indicating whether the value should be returned as a factor of column labels (created if necessary) rather than as numbers ncol() Function in RThe ncol() function in R is used to get the number of columns in a matrix. Find number of rows and columns in a Basic Matrix R # Create an irregular matrix irregular_mat <- matrix(1:9,3,3) # Find the number of rows and columns num_rows_irregular <- nrow(irregular_mat) num_cols_irregular <- ncol(irregular_mat) # Print the results print(paste("Number of rows in irregular matrix:", num_rows_irregular)) print(paste("Number of columns in irregular matrix:", num_cols_irregular)) Output: [1] "Number of rows in irregular matrix: 3"[1] "Number of columns in irregular matrix: 3"Find number of rows and columns in a Irregular Matrix in R R # Create a 3x4 matrix mat <- matrix(1:24,6,4) mat # Find the number of rows and columns num_rows <- nrow(mat) num_cols <- ncol(mat) # Print the results print(paste("Number of rows:", num_rows)) print(paste("Number of columns:", num_cols)) Output: [,1] [,2] [,3] [,4][1,] 1 7 13 19[2,] 2 8 14 20[3,] 3 9 15 21[4,] 4 10 16 22[5,] 5 11 17 23[6,] 6 12 18 24[1] "Number of rows: 6"[1] "Number of columns: 4" Comment More infoAdvertise with us Next Article Getting a Matrix of number of rows in R Programming - row() Function K Kanchan_Ray Follow Improve Article Tags : R Language R Matrix-Function Similar Reads Getting a Matrix of number of columns in R Programming - col() Function col() function in R Language is used to get a matrix which contains the number of columns of the matrix passed to it as argument. Syntax: col(x, as.factor=FALSE) Parameters: x: matrix as.factor: a logical value indicating whether the value should be returned as a factor of column labels (created if 2 min read Get the number of rows of an Object in R Programming - nrow() Function nrow() function in R Language is used to return the number of rows of the specified matrix. Syntax: nrow(x)Parameters: x: matrix, vector, array or data frame  Example 1:  Python3 # R program to illustrate # nrow function # Getting R Biochemical Oxygen Demand Dataset BOD # Calling nrow() function 1 min read Get Transpose of a Matrix or Data Frame in R Programming - t() Function t() function in R Language is used to calculate transpose of a matrix or Data Frame. Syntax: t(x) Parameters: x: matrix or data frame Example 1: Python3 # R program to illustrate # t function # Getting R Biochemical Oxygen Demand Dataset BOD # Calling t() function t(BOD) Output: Time demand 1 1 8.3 1 min read Get or Set Dimensions of a Matrix in R Programming - dim() Function The dim() function in R is used to get or set the dimensions of an object. This function is particularly useful when working with matrices, arrays, and data frames. Below, we will discuss how to use dim() to both retrieve and set dimensions, with examples for better understanding.Syntax: dim(x)Param 2 min read Compute the Sum of Rows of a Matrix or Array in R Programming - rowSums Function rowSums() function in R Programming Language is used to compute the sum of rows of a matrix or an array. It simplifies the process of calculating the sum for each row, especially when dealing with large datasets, and can be applied to both numeric and logical data types.Syntax:rowSums(x, na.rm = FAL 3 min read Like