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
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
2 matches
Mail list logo