So I am new to working with matrices and functions and I am trying to work out how to apply a function to calculate the column means to multiple matrices.
Here is some dummy martices:
A <- matrix(c(1,2,3,4,5,6,7,8,9),nrow=3)
B <- matrix(c(9,8,7,6,5,4,3,2,1),nrow=3)
I have 13 large matrices all different variables, but they all have the same dimensions. I want to get the mean of the columns for each individual matrices. I have worked out how to do this for an individual matrix:
AA <- sapply(1:3, function(x) mean(A [,x], na.rm = TRUE))
But there is probably a more efficient way to apply this to all my matrices than writing this out a dozen times and get the individual outputs, i.e column means for each matrix separately? I have seen some work with using lists of matrices - is this the correct route to go? Apologies if this is a duplicate, i have tried to find a clear example with the correct answer to no avail (feel free to point me in the right direction).