[R] Equivalent to apply(x[,2:5],1,sum) for dataframe

Dieter Menne dieter.menne at menne-biomed.de
Fri Nov 21 19:35:23 CET 2008




Agustin Lobo-4 wrote:
> 
> What's the most correct way of doing the equivalent to
> apply(x[,2:5],1,sum)
> 
> if x is dataframe in which the only numeric fields are
> in columns 2:5 ?
> (using apply returns a character vector)
> 

Could it be that you meant apply(x[,2:5],2,sum)? Not very easy to remember,
when
to use 2 or 1. Also check rowSums and colSums (note the plural forms!) that
can be MUCH faster.

Dieter

-- 
View this message in context: http://www.nabble.com/Equivalent-to-apply%28x-%2C2%3A5-%2C1%2Csum%29-for-dataframe-tp20626483p20627203.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list