小编Jam*_*mes的帖子

如何让分位数与 summarise_at 和 group_by (dplyr) 一起使用

dplyr用于创建按变量级别组织的汇总统计表时,我无法弄清楚计算四分位数的语法而不必重复列名。也就是说,使用调用,例如vars()andlist()与其他函数一起工作,例如mean()and median()but not withquantile()

搜索产生了过时的解决方案,这些解决方案不再有效,因为它们使用了不推荐使用的调用,例如do()和/或funs()

data(iris)
library(tidyverse)

#This works: Notice I have not attempted to calculate quartiles yet
summary_stat <- iris %>% 
  group_by(Species) %>% 
  summarise_at(vars(Sepal.Length), 
               list(min=min, median=median, max=max,
               mean=mean, sd=sd)
               )
A tibble: 3 x 6
  Species      min median   max  mean    sd
  <fct>      <dbl>  <dbl> <dbl> <dbl> <dbl>
1 setosa       4.3    5     5.8  5.01 0.352
2 versicolor   4.9    5.9   7    5.94 0.516
3 virginica    4.9    6.5 …
Run Code Online (Sandbox Code Playgroud)

r quantile dplyr

5
推荐指数
2
解决办法
3010
查看次数

标签 统计

dplyr ×1

quantile ×1

r ×1