Apply a rolling function by group in r (zoo, data.table)
问题 I am having trouble doing something fairly simple: apply a rolling function (standard deviation) by group in a data.table. My problem is that when I use a data.table with rollapply by some column, data.table recycles the observations as noted in the warning message below. I would like to get NAs for the observations that are outside of the window instead of recycling the standard deviations. This is my approach so far using iris, and a rolling window of size 2, aligned to the right: library