Thursday, 22 August 2013

Sum all values in every column of a data.frame in R

Sum all values in every column of a data.frame in R

Given this data set:
Name Height Weight
1 Mary 65 110
2 John 70 200
3 Jane 64 115
I'd like to sum every qualifier columns (Height and Weight) yielding
199 425
The problem is that the qualifiers can be more than just 2 (i.e. more than
just Height and Weight).
I can do this.
res <- c(sum(people$Height),sum(people$Weight))
But it gets too long when the qualifier increase. What's the compact way
to do it?

No comments:

Post a Comment