Rolling Mean/standard deviation with conditions

后端 未结 3 718
滥情空心
滥情空心 2021-01-07 04:47

I have a bit of a question about computing the Rolling Mean/standard deviation based on conditions. To be honest it is more of a syntax question, but since I think it is slo

3条回答
  •  臣服心动
    2021-01-07 05:13

    I met the same problem calculating rolling standard in my data-processing process.So I viewed this site. And I think your problem is using DT$Midquotes not .SD$Midquotes. .SD is a data.table containing the Subset of x’s Data for each group. And roll_sd function is from package"RcppRoll". You can try this way.

    DT[, (sd = roll_sd(.SD$Midquotes, 20, fill=0, align = "right")), by = .(Stock)]
    

提交回复
热议问题