我有一个数据集,我试图找到每个帮派的平均,最小和最大质量,我的代码如下:
mass <- Gangs$Mass_kg
mass.summary <- ddply(Gangs, ~Gang_affiliation, summarise,
minimum = min(mass),
mean = mean(mass),
maximum = max(mass))
输出为:
Gang_affiliation minimum mean maximum
18th Street 86 92 114
Aryan Brotherhood 86 92 114
Black Guerillas 86 92 114
但我真正想要的是每个联盟都有自己的结果。
Gang_affiliation minimum mean maximum
18th Street 86 92 114
Aryan Brotherhood 84 98 121
Black Guerillas 87 95 127
有人可以帮助我吗?
答案 0 :(得分:0)
您应该能够通过
实现这一目标library(dplyr)
Gangs %>% group_by(Gang_affiliation) %>% summarise(minimum = min(mass),
mean = mean(mass)
maximum = max(mass))
我希望这有帮助!