我希望您能够用自定义汇总函数来总结tibble中的每一列,该函数将返回不同大小的tibble,具体大小取决于数据。
假设我的汇总函数如下:
它可以应用于单列,如下所示:
但我无法想出一种使用
使用
当然,实际数据有更多的列... 有什么建议吗?
假设我的汇总函数如下:
mysummary <- function(x) {quantile(x)[1:sample(1:5, 1)] %>% as_tibble}
它可以应用于单列,如下所示:
cars %>% summarise(speed.summary = list(mysummary(speed)))
但我无法想出一种使用
summarise_all
(或类似方法)实现此目标的方法。使用
cars
数据,期望的输出将是:tribble(
~speed.summary, ~dist.summary,
mysummary(cars$speed), mysummary(cars$dist)
)
# A tibble: 1 x 2
speed.summary dist.summary
<list> <list>
1 <tibble [5 x 1]> <tibble [2 x 1]>
当然,实际数据有更多的列... 有什么建议吗?