I need to group a dataframe by one variable and then summarising it by adding the number or rows (I can already do this) and number of columns relative to .25, .5, .75 quantiles of another variable.
In R I would do e.g.:
iris %>%
group_by(Species) %>%
summarise(
quantile(Sepal.Length, c(.25, .75)) %>%
matrix(nrow = 1) %>%
as.data.frame() %>%
setNames(paste0("Sepal.Length", c(.25, .75)))
)
What would be a concise way to write this in Julia using DataFrames and DataFrameMeta? If there's a solution to apply this to multiple columns at once even better.
The closest solution I could find in Julia was:
groupby(iris, :Species) |>
x -> combine(x, :Sepal.Length => x -> [[map(p -> quantile(x, p), (Q25 = 0.25, Q75 = 0.75))] |> DataFrame])
but it just encapsulates the dataframe into a cell, while it should spread it into multiple columns.