Hi: I have an xts object as such:
AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2013-09-09 505.00 507.92 503.48 506.17 12116200 506.17
2013-09-10 506.20 507.45 489.50 494.64 26490200 494.64
2013-09-11 467.01 473.69 464.81 467.71 32031600 467.71
2013-09-12 468.50 475.40 466.01 472.69 14409400 472.69
I try to calculate a rolling mean and attach it to a new column as such
AA["AAPL.Rolling"] <- rollmean(AA[,"AAPL.Adjusted"],12)
Although the rollmean(AA[,"AAPL.Adjusted"],12)
works on its own; I get an error message when I try to attach to a new column.
** also what makes this hard is that the new rolling mean will not have data in every row since the first 12 should be "NA" Can anyone help? Thank you much.
rnorm(12, AA)
gives you 12 observations from a random normal distribution withmean=AA[1:12,1]
and sd=1. That's not even close to a rolling mean. And you're trying to add a zoo object as a column of an xts object? Why do you think that should work?