0

Is there a function like rollapply for data.frame [duplicate] R rolling equation on data.frame

R rolling equation on data.frame Is there a function like rollapply for data.frame

https://www.rdocumentation.org/packages/zoo/versions/1.8-0/topics/rollapply

=========================================================================== I want to make column named '3mean' contains last 3 periods mean price.

As you know, python pandas offers roll_sum, roll_mean function for DataFrame. But I can't find such thing in R.

I have read rollapply function example·question but that is not a dataframe thing or I could not understand because of the complexity.

How can I make a 3mean column?

Thank you.

library(dplyr)
library(quantmod)
library(TTR)
today <- Sys.Date()
kq <- getSymbols("^kq11", 
             from = today-30, 
             to = today, 
             auto.assign = F)

head(kq,15)



> head(kq,15)
       KQ11.Open KQ11.High KQ11.Low KQ11.Close
2017-06-19    672.72    675.71   672.25     675.44
2017-06-20    678.72    678.82   669.41     669.41
2017-06-21    668.41    668.44   662.68     665.77
2017-06-22    667.99    668.36   663.26     663.28
2017-06-23    665.19    669.05   665.02     668.93
2017-06-26    670.59    670.78   667.71     668.36
2017-06-27    671.70    673.13   670.87     672.63
2017-06-28    671.26    672.36   665.89     665.89
2017-06-29    670.10    670.56   666.00     668.00
2017-06-30    665.67    669.12   665.57     669.04
2017-07-03    671.17    671.17   660.04     660.97
2017-07-04    662.17    663.85   654.06     656.19
www
  • 38,575
  • 12
  • 48
  • 84
Commaeng
  • 75
  • 1
  • 2
  • 10

0 Answers0