I am trying to shift one column of an xts time series to the left in R (please see the code below). The lag shifts nicely to the right, but I want it to line up with the rolling mean. Using a negative number says: "n must be positive".
#rm(list=ls())#dev.off(dev.list()["RStudioGD"])library(roll) # do not use library(RcppRoll)!getSymbols("^GSPC",src="yahoo",from="2015-01-01",to = "2020-06-04")y<-GSPC$GSPC.Closestandardize<-function(ts) { as.xts(apply(ts, 2, function(x) x / x[1])) }y<-standardize(GSPC$GSPC.Close)n=400y$m<-rollmean(y$GSPC.Close,k=n)y$rolling<-roll_sd(y$GSPC.Close,n)y$lag<-lag(y$rolling,n/2) # how to go left?plot(y)ts.plot(y,col=1:4)