[R] Column sums from a data frame (without the headers)

Gabor Csardi csardi at rmki.kfki.hu
Fri Feb 29 18:10:53 CET 2008


colSums gives you exactly what you want, but the vector is *named*.
You can use it like a not-named numeric vector, without much trouble.
If you still want to get rid of the names see ?unname

G.

On Fri, Feb 29, 2008 at 12:02:46PM -0500, Jason Horn wrote:
> Does anyone know how to get a vector of column sum from a data frame?   
> You can use colSums(), but this gives you a object of type "numeric"  
> with the column labels in the first row, and the sums in the second  
> row.  I just want a vector of the sums, and I can't figure out a way  
> to index the "numeric" object.
> 
> Thanks!
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Csardi Gabor <csardi at rmki.kfki.hu>    UNIL DGM



More information about the R-help mailing list