Hi,
So let's say I have a function f
that returns the min, max, and median of a numerical vector x as a vector of 3 values.
f <- function(x) {
c( min(x), max(x), median(x) )
}
Is there a way to use f
in a dplyr::summarise
call to get these 3 statistics as independent variables as one would get using the following "full" call?
require(tidyverse)
set.seed(12345)
df <- data.frame(
x = rnorm(1000),
y = sample(1:2, 1000, replace = TRUE)
)
df %>%
group_by(y) %>%
summarise(
min = min(x),
max = max(x),
median = median(x)
)