How to use Aggregate function in R

北慕城南 提交于 2019-11-27 22:31:00
aggregate(FLOWS ~ SPORT, dat, function(x) sum(as.numeric(x)))

where dat is the name of your matrix.

Here, the function is.numeric is necessary to transform the second column into numbers.

Assuming your dataframe is named "sport_data", I think you just want:

aggregate(sport_data, sport_data$SPORT, sum)

If you just have individual counts (that are all equal to 1), then "tabulate" may be a simpler option.

Please let us know what kind of errors you are getting. (if this doesn't work, or in the future, in your question)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!