I want to put the data.table function dcastin a function that can handle its own number / order of aggregate functions. This is why I need to pass aggregated functions as function parameters dcast. Parameters must be defined out dcast. How can i do this?
This works well, but I want to define aggregate functions outside of dcast.
dt = data.table(x = sample(5, 20, TRUE), y = sample(2, 20, TRUE),
z = sample(letters[1:2], 20, TRUE), d1 = runif(20), d2 = 1L
dcast(dt, x + y ~ z, fun = list(sum, min), value.var = "d1")
I tried this method:
func <- list(sum, min)
dcast(dt, x + y ~ z, fun = func, value.var = "d1")
Then I get this error message:
Error in eval (expr, envir, enc): could not find function "func"
source
share