[R] list of matrices

arun smartpink111 at yahoo.com
Wed Jan 2 23:34:05 CET 2013

Check this link

list1<-lapply(1:3,function(i) matrix(sample(1:10,6,replace=TRUE),ncol=i) )
lapply(list1,function(x) colMeans(x,na.rm=TRUE))
#[1] 6.666667

#[1] 6.333333 6.000000
#[1] 7.0 9.0 7.5

----- Original Message -----
From: eliza botto <eliza_botto at hotmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Sent: Wednesday, January 2, 2013 5:16 PM
Subject: [R] list of matrices

dear useRs,
i have a list containing 16 matrices. i want to calculate  the column mean of each of them.
i tried
>sr <- lapply(s,function(x) colMeans(x, na.rm=TRUE))
but i am getting the following error
>Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric
can it be done in any other way? and why i am getting this error??
thanks in advance..
    [[alternative HTML version deleted]]

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list