Re: [R] using dcast with a function of multiple arguments

2015-07-21 Thread Thierry Onkelinx
Here is a solution using dplyr require(data.table) dt - as.data.table(mtcars) library(dplyr) library(tidyr) dt %% group_by(carb, cyl) %% summarise(WM = weighted.mean(x = mpg, w = wt)) %% spread(cyl, WM) Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research

[R] using dcast with a function of multiple arguments

2015-07-20 Thread Bos, Roger
I am trying to figure out how to use dcast.data.table with a function with multiple arguments. Here is my reproducible example for a simple function of one argument: require(data.table) dt - as.data.table(mtcars) dcast.data.table(dt, carb ~ cyl, value.var='mpg', fun=mean) If I instead want to