[R] mean vs sum behavior

Emmanuel Castella Emmanuel.Castella at leba.unige.ch
Mon Mar 31 18:41:51 CEST 2008


Dear all
Could someone explain me why
lapply(split(x,fac),mean)
returns means per levels of fac for each column of x
whereas
lapply(split(x,fac),sum)
does not return sums per level of fac and columns of x, but adds all 
columns together?
Hence, how can I get sum to behave as mean in this instance?
Thank you very much in advance
E. Castella



More information about the R-help mailing list