Calculate the mean of columns of the array in R
In this approach, the user needs to call the colmean() function with the name of the array with its dimensions as the parameter to get the mean of the columns of the given array in the R language.
Syntax:
colMeans(data, dims )
where,
- data is the input array
- dims stands for dimensions
Example:
in this example, we will create an array with 3 dimensions with 1 to 12 elements and calculate column means using the colmeans() function in the R programming language.
R
# Initializing a 3D array data= array (1:12, c (2, 3, 3)) # colmeans for one dimension print ( colMeans (data, dims = 1)) # colmeans for two dimension print ( colMeans (data, dims = 2)) |
Output:
[,1] [,2] [,3] [1,] 1.5 7.5 1.5 [2,] 3.5 9.5 3.5 [3,] 5.5 11.5 5.5 [1] 3.5 9.5 3.5
How to Use ColMeans Function in R?
In this article, we will discuss how to use the ColMeans function in R Programming Language.
Contact Us