How can I refer to multiple aggregation functions in data.table dcast?

Question

I want to put data.table dcast function into a function, which can handle custom number/order of aggregate functions. That is why I need to pass aggregate functions as parameters to dcast function. The parameters need to be defined outside dcast. How could I do this?

This works well, but I wan to define the 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, enclos) : could not find function "func"


Show source
| R   | data.table   | dcast   2017-03-16 23:03 0 Answers

Answers to How can I refer to multiple aggregation functions in data.table dcast? ( 0 )

Leave a reply to - How can I refer to multiple aggregation functions in data.table dcast?

◀ Go back