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 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 Like