I am looking to summarize each column in a tibble with a custom summary function that will return different sized tibbles depending on the data.
Let’s say my summary function is this:
mysummary <- function(x) {quantile(x)[1:sample(1:5, 1)] %>% as_tibble}
It can be applied to one column as such:
cars %>% summarise(speed.summary = list(mysummary(speed)))
But I can't figure out a way to achieve this using summarise_all
(or something similar).
Using the cars
data, the desired output would be:
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]>
Of course the actual data has many more columns...
Suggestions?
Is this what you had in mind?
Created on 2018-01-27 by the reprex package (v0.1.1.9000).
We can use