I have a section in my Shiny app that generates a list.
names of the list are column names of the dataframe
we will calculate on,
list items contain the ca
To turn Uwe's answer into a function I did this:
Summarystats <- function(statlist, dataframe, group) {
statlist %>%
names() %>%
lapply(
function(.col) lapply(
statlist[[.col]],
function(.fct) sprintf("%s.%s = %s(%s)", .col, .fct, .fct, .col))) %>%
unlist() %>%
paste(collapse = ", ") %>%
sprintf("as.data.table(dataframe)[, .(%s), by = group]", .) %>%
parse(text = .) %>%
eval()
}
Now I can call:
Summarystats(mylist, mtcars, 'cyl')
allowing me to call a summary table for whichever dataframe and grouping the user wants in my Shiny App.