I am trying to move some of my slower processes in dplyr to using data.table, however can not seem to find an efficient way of using a \"mutate_at\" type approach in data.ta
And also from Apply multiple functions to multiple columns in data.table
f <- function(x) lapply(c(Roll.Mean.Week=7L, Roll.Mean.Two.Week=14L),
function(n) rollapplyr(x, width=n, mean, fill=0L, na.rm=TRUE, partial=TRUE))
DT[, unlist(lapply(.SD, f), recursive=FALSE), A, .SDcols=B:C]
output:
A B._Roll.Mean.Week B._Roll.Mean.Two.Week C._Roll.Mean.Week C._Roll.Mean.Two.Week
1: 1 1 1 101 101
2: 1 2 2 102 102
3: 1 3 3 103 103
4: 1 4 4 104 104
5: 1 5 5 105 105
6: 1 6 6 106 106
7: 1 7 7 107 107
8: 1 9 8 109 108
9: 1 11 9 111 109
10: 1 13 10 113 110
[trunc...]