help charlie
library(data.table) | |
dt = data.table(i=rep(1:5, each=10), t=rep(1:5, times=2), x=runif(50), key=c('i', 't')) | |
myfunc = function(x) { | |
return(data.frame(sum=sum(x), mean=mean(x))) | |
} | |
dt[, myfunc(x), by=.(i, t)] | |
myfunc2 = function(df) { | |
setDF(df) | |
return(data.frame(sum=sum(df$x), mean=mean(df$x))) | |
} | |
dt[, myfunc2(.SD), by=.(i, t)] | |
myfunc3 = function(dt) { | |
df = data.frame(dt) | |
return(data.frame(sum=sum(df$x), mean=mean(df$x))) | |
} | |
dt[, myfunc3(.SD), by=.(i, t)] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment