Last active
September 12, 2018 23:05
-
-
Save jsams/8c1dc3a98ed407f8fbecd5b351ea75f6 to your computer and use it in GitHub Desktop.
help charlie
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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