Skip to content
Prev 314138 / 398513 Next

colmeans not working

Dear Eliza,

It didn't change the result.
res<-list(read.table(text="
???? month????? 2005????? 2006????? 2008????? 2009
????? 1 1.7360776 0.8095275 1.6369044 0.8195241
????? 2 0.6962079 3.8510720 0.4319758 2.3304495
????? 3 1.0423625 2.7687266 0.2904245 0.7015527
????? 4 2.4158326 1.2315324 1.4287387 1.5701019
",sep="",header=TRUE),read.table(text="
?? month?????? 2008????? 2009????? 2010
????? 1? 1.4737028? 2.314878? 2.672661
????? 2? 1.6700918? 2.609722? 2.112421
????? 3? 3.2387775? 7.305766? 6.939536
????? 4? 6.7063592 18.745256 13.278218
",sep="",header=TRUE))
?names(res)<-c("EE","WW")
res<-lapply(res,function(x) {names(x)<-gsub("X","",names(x));x})
res
#$EE
?# month????? 2005????? 2006????? 2008????? 2009
#1???? 1 1.7360776 0.8095275 1.6369044 0.8195241
#2???? 2 0.6962079 3.8510720 0.4319758 2.3304495
#3???? 3 1.0423625 2.7687266 0.2904245 0.7015527
#4???? 4 2.4158326 1.2315324 1.4287387 1.5701019

#$WW
?# month???? 2008????? 2009????? 2010
#1???? 1 1.473703? 2.314878? 2.672661
#2???? 2 1.670092? 2.609722? 2.112421
#3???? 3 3.238777? 7.305766? 6.939536
#4???? 4 6.706359 18.745256 13.278218

lapply(res,function(x) colMeans(x[,-1]))
#$EE
#???? 2005????? 2006????? 2008????? 2009 
#1.4726202 2.1652146 0.9470108 1.3554070 
#
#$WW
#??? 2008???? 2009???? 2010 
#3.272233 7.743906 6.250709 

?lapply(res,function(x) rowMeans(x[,-1]))
#$EE
#[1] 1.250508 1.827426 1.200767 1.661551
#
#$WW
#[1]? 2.153747? 2.130745? 5.828026 12.909944
A.K.