Dplyr计数逐个组,然后分配每个

时间:2017-10-25 14:45:26

标签: r dplyr mean quantile

我遇到dplyr问题,或者我无法弄清楚如何正确编码分位数部分。

我有一个数据,我希望按X和Y分组,然后计算每组中a的均值

dmean %>%
  group_by(x,y) %>%
   summarise(mean=mean(a))

这部分有效,没问题。 如何继续使用代码获得每组最低10%和最高10%的百分位数?

1 个答案:

答案 0 :(得分:3)

您可以在df <- data.frame( ID = as.factor(c(20260, 11893, 54216, 11716, 53368, 46196, 40007, 20970, 11802, 46166, 23615, 11865, 16138, 64789, 43211, 66539)), Score = c(9,7,6,2,10,7,8,10,6,7,7,9,9,9,10,8), Remark = as.factor(c("PASS","PASS","FAIL","FAIL","PASS","PASS","PASS","PASS","FAIL","PASS","PASS","PASS","PASS","PASS","PASS","PASS")) ) df[df$Remark == "PASS", 1:2] ID Score 1 20260 9 2 11893 7 5 53368 10 6 46196 7 7 40007 8 8 20970 10 10 46166 7 11 23615 7 12 11865 9 13 16138 9 14 64789 9 15 43211 10 16 66539 8 内添加多个表达式,如下所示:

summarise