I want to do a vector assignment of specific dates that happen to be in the reverse order of the xts's index like so:
# create xts index and an all-zeroes instance of xts
idx <- seq.Date( as.Date("2011-01-01"), as.Date("2011-10-01"), by='month' )
x <- xts( seq_along(idx), idx )
# create a dataframe with "yearmo" and some data. note reverse order of yermo from idx
d <- data.frame( yearmo=201110:201101, data=10:1 )
# assign d$data to "proper" location in timeseries
dateVec <- as.Date( paste0( d$yearmo, "01" ), format="%Y%m%d" )
x[ dateVec ] <- d$data
Based on what I know about vector operations in R, this should work to assign each value of the timeseries the corresponding value in the dataframe, where "2011-01-01"
's value would be 1. Instead, the values are reversed, as below:
[,1]
2011-01-01 10
2011-02-01 9
2011-03-01 8
2011-04-01 7
2011-05-01 6
2011-06-01 5
2011-07-01 4
2011-08-01 3
2011-09-01 2
2011-10-01 1
Whereas I'm expecting
[,1]
2011-01-01 1
2011-02-01 2
2011-03-01 3
2011-04-01 4
2011-05-01 5
2011-06-01 6
2011-07-01 7
2011-08-01 8
2011-09-01 9
2011-10-01 10
I have checked the xts documentation and some of the similar questions, but I can't find anyone who's run in to a similar thing. What is the proper way to assign multiple xts
values at once? What am I missing?