Monday, 26 August 2013

R data.table with rollapply

R data.table with rollapply

Has anyone ever worked with trying to do rolling statistics using
data.table grouping?
For example, given the following code:
DT = data.table(x=rep(c("a","b","c"),each=2), y=c(1,3), v=1:6)
setkey(DT, y)
stat.ror <- DT[,rollapply(v, width=1, by=1, mean, na.rm=TRUE), by=y];

No comments:

Post a Comment