Calculate the Sum of Matrix or Array columns in R Programming - colSums() Function Last Updated : 03 Jun, 2020 Comments Improve Suggest changes Like Article Like Report colSums() function in R Language is used to compute the sums of matrix or array columns. Syntax: colSums (x, na.rm = FALSE, dims = 1) Parameters: x: matrix or array dims: this is integer value whose dimensions are regarded as ‘columns’ to sum over. It is over dimensions 1:dims. Example 1: Python3 # R program to illustrate # colSums function # Initializing a matrix with 3 # rows and 3 columns x <- matrix(rep(1:9), 3, 3) # Getting the matrix representation x # Calling the colSums() function colSums(x) Output: [, 1] [, 2] [, 3] [1, ] 1 4 7 [2, ] 2 5 8 [3, ] 3 6 9 [1] 6 15 24 Example 2: Python3 # R program to illustrate # colSums function # Initializing a 3D array x <- array(1:12, c(2, 3, 3)) # Getting the array representation x # Calling the colSums() function colSums(x, dims = 1) colSums(x, dims = 2) Output: ,, 1 [, 1] [, 2] [, 3] [1, ] 1 3 5 [2, ] 2 4 6,, 2 [, 1] [, 2] [, 3] [1, ] 7 9 11 [2, ] 8 10 12,, 3 [, 1] [, 2] [, 3] [1, ] 1 3 5 [2, ] 2 4 6 [, 1] [, 2] [, 3] [1, ] 3 15 3 [2, ] 7 19 7 [3, ] 11 23 11 [1] 21 57 21 Comment More infoAdvertise with us Next Article Calculate the Sum of Matrix or Array columns in R Programming - colSums() Function K Kanchan_Ray Follow Improve Article Tags : R Language R Matrix-Function Similar Reads Calculate the Mean of each Column of a Matrix or Array in R Programming - colMeans() Function colMeans() function in R Language is used to compute the mean of each column of a matrix or array. Syntax: colMeans(x, dims = 1) Parameters: x: array of two or more dimensions, containing numeric, complex, integer or logical values, or a numeric data frame dims: integer value, which dimensions are r 2 min read Calculate the cross-product of a Matrix in R Programming - crossprod() Function crossprod() function in R Language is used to return the cross-product of the specified matrix. Syntax: crossprod(x) Parameters: x: numeric matrix Example 1: Python3 # R program to illustrate # crossprod function # Initializing a matrix with # 2 rows and 2 columns x <- matrix(1:4, 2, 2) # Getting 1 min read Calculate Trace of a Matrix in R Programming - tr() Function tr() function in R Language is used to calculate the trace of a matrix. Trace of a matrix is the sum of the values on the main diagonal(upper left to lower right) of the matrix. Syntax: tr(x) Parameters: x: Matrix Example 1: Python3 1== # R program to calculate # trace of a matrix # Loading library 1 min read Calculate Cumulative Sum of a Numeric Object in R Programming - cumsum() Function The cumulative sum can be defined as the sum of a set of numbers as the sum value grows with the sequence of numbers. cumsum() function in R Language is used to calculate the cumulative sum of the vector passed as argument. Syntax: cumsum(x) Parameters: x: Numeric Object Example 1: Python3 # R pr 1 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 Calculate the cross-product of the Transpose of a Matrix in R Programming - tcrossprod() Function tcrossprod() function in R Language is used to return the cross-product of the transpose of the specified matrix. Syntax: tcrossprod(x) Parameters: x: numeric matrix Example 1: Python3 # R program to illustrate # tcrossprod function # Initializing a matrix with # 2 rows and 2 columns x <- matrix( 1 min read 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 Calculate the Mean of each Row of an Object in R Programming â rowMeans() Function rowMeans() function in R Language is used to find out the mean of each row of a data frame, matrix, or array. Syntax: rowMeans(data) Parameter: data: data frame, array, or matrix Example 1 Python3 1== # R program to illustrate # rowMean function # Create example values # Set seed set.seed(1234) # Cr 1 min read Calculate Cumulative Product of a Numeric Object in R Programming â cumprod() Function cumprod() function in R Language is used to calculate the cumulative product of the vector passed as argument. Syntax: cumprod(x) Parameters: x: Numeric Object Example 1: Python3 1== # R program to illustrate # the use of cumprod() Function # Calling cumprod() Function cumprod(1:4) cumprod(-1:-6) Ou 1 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 Like