Jason Horn
2008-Feb-29 19:21 UTC
[R] Column sums from a data frame (without the column headers)
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!
jim holtman
2008-Feb-29 22:21 UTC
[R] Column sums from a data frame (without the column headers)
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Here is an example; I am not sure what problem you are having with 'indexing' since you did not show an example.> x <- data.frame(a=1:10, b=21:30, c=41:50) > y <- colSums(x) > ya b c 55 255 455> # indexing into y > y[1]a 55> # same as > y["a"]a 55> >On Fri, Feb 29, 2008 at 2:21 PM, Jason Horn <jhorn at bu.edu> 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? Tell me what you want to do, not how you want to do it.