Conditional table sum on r -
this question has answer here:
- how sum variable group? 9 answers
what i'm trying sum table variable if 1 true, example:
this part of table:
school sex age studytime 1 2 m 18 2,1 1 1 m 19 2,8 1 2 f 18 2,6 1 3 m 17 2,7 1 3 f 17 1,1 1 4 f 19 3,8 1 1 m 20 2,5
and need sum studytime each sex, this:
sex studytime m 10,1 f 7,5
a base r method based on aggregate
below:
aggregate(x$studytime,by=list(sex=x$sex),sum)
Comments
Post a Comment