Is it possible to reshape on multiple columns by passing a list of column names (value.var) along with a list of aggregation functions (fun.aggregate). This works well when those lists are explicitly passed to the function arguments. It appears to result in an error condition if the lists are passed as variables.
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)
funs = list(sum, mean)
vars = list("d1", "d2")
dcast(dt, x + y ~ z, fun=funs, value.var=vars)
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] testthat_2.0.0 data.table_1.11.4
loaded via a namespace (and not attached):
[1] compiler_3.5.0 magrittr_1.5 R6_2.2.2 tools_3.5.0 rlang_0.2.1
Is it possible to reshape on multiple columns by passing a list of column names (
value.var) along with a list of aggregation functions (fun.aggregate). This works well when those lists are explicitly passed to the function arguments. It appears to result in an error condition if the lists are passed as variables.