I am in the process of converting to data.table and so far have not been able to find a data.table way to create a table with summary statistics based on a self-defined function. Until now, I have used dplyr to accomplish this, for which I provide the code below. Is it possible to achieve a similar thing in a neat way using data.table?
library(dplyr)
library(mlbench)
data(BostonHousing)
df <- BostonHousing
fun_stats <- function(x) {
min <- min(x, na.rm = TRUE)
max <- max(x, na.rm = TRUE)
mean <- mean(x, na.rm = TRUE)
summary <- list(min = min, max = max, mean = mean)
}
stats <- df %>%
select_if(is.numeric) %>%
purrr::map(fun_stats) %>%
bind_rows(., .id = "var") %>%
mutate(across(where(is.numeric)))