Getting a Matrix of number of columns in R Programming - col() Function Last Updated : 03 Jun, 2020 Comments Improve Suggest changes Like Article Like Report 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 necessary) rather than as numbers Example 1: Python3 # R program to illustrate # col function # Initializing a matrix with # 2 rows and 2 columns x <- matrix(c(1, 2, 3, 4), 2, 2) # Getting the matrix representation x # Calling the col() function col(x) Output: [, 1] [, 2] [1, ] 1 3 [2, ] 2 4 [, 1] [, 2] [1, ] 1 2 [2, ] 1 2 Example 2: Python3 # R program to illustrate # col function # Initializing a matrix with # 3 rows and 3 columns x <- matrix(rep(1:9), 3, 3) # Getting the matrix representation x # Calling the col() function col(x) Output: [, 1] [, 2] [, 3] [1, ] 1 4 7 [2, ] 2 5 8 [3, ] 3 6 9 [, 1] [, 2] [, 3] [1, ] 1 2 3 [2, ] 1 2 3 [3, ] 1 2 3 Comment More infoAdvertise with us Next Article Getting a Matrix of number of columns in R Programming - col() Function K Kanchan_Ray Follow Improve Article Tags : R Language R Matrix-Function Similar Reads Getting a Matrix of number of rows in R Programming - row() Function 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 w 2 min read Get the number of columns of an Object in R Programming - ncol() Function ncol() function in R Language is used to return the number of columns of the specified matrix. Syntax: ncol(x)Parameters: x: matrix, vector, array or data frame  Example 1:  Python3 # R program to illustrate # ncol function # Getting R Biochemical Oxygen Demand Dataset BOD # Calling ncol() functi 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 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 the position of the maximum element in each Row of a Matrix in R Programming - max.col() Function max.col() function in R Language check for maximum value in each row and returns the column no. for it. Syntax: max.col(x, ties.method) Parameters: x: Numeric matrix ties.method: It takes random, first, and last as value and returns the position accordingly in case of a tie. Example 1: Python3 1== # 1 min read Like