Skip to content
Prev 309720 / 398503 Next

override date in xts time series

HI Eric,

The example dataset seems to be working for me, but there is some problem with the order
y.1<-xts(1:6, as.POSIXct(y, format=fmt)) 
?y.1
#??????????????????? [,1]
#2004-04-04 01:00:00??? 4
#2004-04-04 01:15:00??? 1
#2004-04-04 01:30:00??? 2
#2004-04-04 01:30:00??? 5
#2004-04-04 01:45:00??? 3
#2004-04-04 03:30:00??? 6

index(y.1)<-update(index(y.1),month=unique(month(index(x.1))))
?y.1
#??????????????????? [,1]
#2004-01-04 01:00:00??? 4
#2004-01-04 01:15:00??? 1
#2004-01-04 01:30:00??? 2
#2004-01-04 01:30:00??? 5
#2004-01-04 01:45:00??? 3
#2004-01-04 03:30:00??? 6
I am using R 2.15.


If you look at the index of y.1, it is not unique.? I think you need unique index/timestamps to get it working correctly.
I think this is where it got into problems:
as.POSIXct(y,format=fmt)
#[1] "2004-04-04 01:15:00 EST" "2004-04-04 01:30:00 EST"
#[3] "2004-04-04 01:45:00 EST" "2004-04-04 01:00:00 EST"
#[5] "2004-04-04 01:30:00 EST" "2004-04-04 03:30:00 EDT"

Here, you can see that some of them are duplicated.

Now, see the difference:
as.POSIXct(y,format=fmt,tz="EST")
#[1] "2004-04-04 01:15:00 EST" "2004-04-04 01:30:00 EST"
#[3] "2004-04-04 01:45:00 EST" "2004-04-04 02:00:00 EST"
#[5] "2004-04-04 02:30:00 EST" "2004-04-04 03:30:00 EST"

Now, I am trying again:

y.1<-xts(1:6, as.POSIXct(y, format=fmt,tz="EST")) 
#You will get a warning message
#Warning message:
#timezone of object (EST) is different than current timezone (). 

index(y.1)<-update(index(y.1),month=unique(month(index(x.1))))
y.1
#??????????????????? [,1]
#2004-01-04 01:15:00??? 1
#2004-01-04 01:30:00??? 2
#2004-01-04 01:45:00??? 3
#2004-01-04 02:00:00??? 4
#2004-01-04 02:30:00??? 5
#2004-01-04 03:30:00??? 6

I hope this helps.


A.K.