Skip to Content

Setting an xts Index

Build an xts object with two rows.

library(xts)   
junk<-xts(c(1,2),as.Date(c("2010-01-01","2010-05-01")))   
junk   
>            [,1]
> 2010-01-01    1   
> 2010-05-01    2   

Why doesn't the following change the index for the first row?

time(junk[1])<-as.Date("2010-02-01")   
junk   
>            [,1]
> 2010-01-01    1   
> 2010-05-01    2   

I realize that the following works, but why doesn't the above work?

time(junk)[1]<-as.Date("2010-02-01")   
junk   
>            [,1]
> 2010-02-01    1   
> 2010-05-01    2   

Thanks,

Bill