Re: [R] override date in xts time series

2012-11-03 Thread Eric Morway
Hello Arun, 

I too am using R 2.15 and am unable to get the same result as you.  You 
will notice in the R code that follows that when I use 'update' the time 
in the xts object goes haywire.  For example, 2004-04-04 01:15:00 EST 
gets converted to 2004-01-03 22:15:00 PST (see below).  Because I can't 
get the result you showed me in your previous response, and maybe you 
won't be able to get this result, I've resorted back to your other 
suggestion using gsub.  I don't have a good handle on regular expressions 
and was wondering if in the last line of code below, the replace month is 
'hardwired'?  In other words, could \\101\\2 somehow be replaced with 
unique(month(index(x.1)))in the last line of code below so that x.1 is 
providing the replacement month, rather than have it fixed?  Or perhaps 
I've misunderstood the regular expression, which is entirely possible.


sessionInfo()
#R version 2.15.2 (2012-10-26)
#Platform: x86_64-w64-mingw32/x64 (64-bit)

library(xts)
library(lubridate)

x.Date - rep(1/1/2004,times=5)
x.Times- c(01:15:00, 01:30:00, 01:45:00,
   02:00:00, 02:30:00, 03:00:00, 03:15:00)
x-paste(x.Date,x.Times)

y.Date - rep(4/4/2004,times=4)
y.Times- c(01:15:00, 01:30:00, 01:45:00,
   02:00:00, 02:30:00, 03:30:00)

y-paste(y.Date,y.Times)

fmt - %m/%d/%Y %H:%M:%S
x.1-xts(1:7, as.POSIXct(x, format=fmt, tz = EST))
y.1-xts(1:6, as.POSIXct(y, format=fmt, tz = EST))

y.1

#[,1]
#2004-04-04 01:15:001
#2004-04-04 01:30:002
#2004-04-04 01:45:003
#2004-04-04 02:00:004
#2004-04-04 02:30:005
#2004-04-04 03:30:006
#Warning message:
#timezone of object (EST) is different than current timezone (). 

index(y.1)
# 2004-04-04 01:15:00 EST 2004-04-04 01:30:00 EST
# 2004-04-04 01:45:00 EST 2004-04-04 02:00:00 EST
# 2004-04-04 02:30:00 EST 2004-04-04 03:30:00 EST

index(y.1)-update(index(y.1),month=unique(month(index(x.1 
index(y.1)

# 2004-01-03 22:15:00 PST 2004-01-03 22:30:00 PST
# 2004-01-03 22:45:00 PST 2004-01-03 23:00:00 PST
# 2004-01-03 23:30:00 PST 2004-01-04 00:30:00 PST


index(y.1)-as.POSIXct(gsub((.*\\-).*(\\-.*),\\101\\2,index(y.1))) 
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] override date in xts time series

2012-11-03 Thread Eric Morway
Sys.setenv(TZ=GMT) did the trick!  Thank you very much.  I'll continue 
to work the larger problem with this option.

Out of curiosity, however, can the following code be modified so that the 
replacement argument is informed by the month of x.1?:

index(y.1)-as.POSIXct(gsub((.*\\-).*(\\-.*),\\101\\2,index(y.1))) 

Something to the tune of the following seems to work, but is it robust?:

txt-paste(\\10,as.character(unique(month(index(x.1,\\2,sep=)
index(y.1)-as.POSIXct(gsub((.*\\-).*(\\-.*),txt,index(y.1))) 
index(y.1)
# 2004-01-04 01:15:00 PST 2004-01-04 01:30:00 PST
# 2004-01-04 01:45:00 PST 2004-01-04 02:00:00 PST
# 2004-01-04 02:30:00 PST 2004-01-04 03:30:00 PST

What would the gsub 'pattern' string be to replace the day, if I may ask? 
I'm not trying to push my luck, but the gsub approach is new to me and 
don't quite follow everything that is going on.

-Eric
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] override date in xts time series

2012-11-03 Thread arun
Hi,
Sorry, I forgot to answer the second question.
 txt-paste(\\10,unique(month(index(x.1))),\\2,sep=)  #without the 
as.character() also should work
#because
 str(paste(\\10,unique(month(index(x.1))),\\2,sep=)) # it returns a 
character
# chr \\101\\2

#Here too:
str(paste(10,unique(month(index(x.1))),2,sep=))
# chr 1012
#According to the description in paste()
Concatenate vectors after converting to character. 


 as.POSIXct(gsub((.*\\-).*(\\-.*),txt,index(y.1))) 
#[1] 2004-01-04 01:15:00 EST 2004-01-04 01:30:00 EST
#[3] 2004-01-04 01:45:00 EST 2004-01-04 02:00:00 EST
#[5] 2004-01-04 02:30:00 EST 2004-01-04 03:30:00 EST

#Now, suppose if I want to change both the month and day from the original y.1
 index(y.1)-as.POSIXct(gsub((.*\\-).*(\\-).*(\\s.*),\\101\\207\\3,index(y.1)))
 #Here, the month will be 01 and day 07
 y.1
#    [,1]
#2004-01-07 01:15:00    1
#2004-01-07 01:30:00    2
#2004-01-07 01:45:00    3
#2004-01-07 02:00:00    4
#2004-01-07 02:30:00    5
#2004-01-07 03:30:00    6
Hope it helps.
A.K.








From: Eric Morway emor...@usgs.gov
To: arun smartpink...@yahoo.com 
Cc: R help r-help@r-project.org 
Sent: Saturday, November 3, 2012 12:32 PM
Subject: Re: [R] override date in xts time series


Sys.setenv(TZ=GMT) did
the trick!  Thank you very much.  I'll continue to work the larger
problem with this option. 

Out of curiosity, however, can the following
code be modified so that the replacementargument is informed by the month
of x.1?: 

index(y.1)-as.POSIXct(gsub((.*\\-).*(\\-.*),\\101\\2,index(y.1)))  

Something to the tune of the following
seems to work, but is it robust?: 

txt-paste(\\10,as.character(unique(month(index(x.1,\\2,sep=) 
index(y.1)-as.POSIXct(gsub((.*\\-).*(\\-.*),txt,index(y.1)))  
index(y.1) 
# 2004-01-04 01:15:00 PST 2004-01-04
01:30:00 PST 
# 2004-01-04 01:45:00 PST 2004-01-04
02:00:00 PST 
# 2004-01-04 02:30:00 PST 2004-01-04
03:30:00 PST 

What would the gsub 'pattern' string
be to replace the day, if I may ask?  I'm not trying to push my luck,
but the gsub approach is new to me and don't quite follow everything that
is going on. 

-Eric

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] override date in xts time series

2012-11-03 Thread arun
HI,

Could you check whether you are getting the same result with tz=GMT?
as.POSIXct(x,format=fmt,tz=GMT)
#[1] 2004-01-01 01:15:00 GMT 2004-01-01 01:30:00 GMT
#[3] 2004-01-01 01:45:00 GMT 2004-01-01 02:00:00 GMT
#[5] 2004-01-01 02:30:00 GMT 2004-01-01 03:00:00 GMT
#[7] 2004-01-01 03:15:00 GMT
 as.POSIXct(y,format=fmt,tz=GMT)
#[1] 2004-04-04 01:15:00 GMT 2004-04-04 01:30:00 GMT
#[3] 2004-04-04 01:45:00 GMT 2004-04-04 02:00:00 GMT
#[5] 2004-04-04 02:30:00 GMT 2004-04-04 03:30:00 GMT

x.1-xts(1:7,as.POSIXct(x,format=fmt,tz=GMT))
 x.1
#    [,1]
#2004-01-01 01:15:00    1
#2004-01-01 01:30:00    2
#2004-01-01 01:45:00    3
#2004-01-01 02:00:00    4
#2004-01-01 02:30:00    5
#2004-01-01 03:00:00    6
#2004-01-01 03:15:00    7
#Warning message:
#timezone of object (GMT) is different than current timezone (). 
 y.1-xts(1:6,as.POSIXct(y,format=fmt,tz=GMT))
 y.1
#    [,1]
#2004-04-04 01:15:00    1
#2004-04-04 01:30:00    2
#2004-04-04 01:45:00    3
#2004-04-04 02:00:00    4
#2004-04-04 02:30:00    5
#2004-04-04 03:30:00    6
#Warning message:
#timezone of object (GMT) is different than current timezone (). 

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


#Here is where the problem occurs


index(y.1)-update(index(y.1),month=unique(month(index(x.1  
y.1
#    [,1]
#2004-01-03 20:15:00    1
#2004-01-03 20:30:00    2
#2004-01-03 20:45:00    3
#2004-01-03 21:00:00    4
#2004-01-03 21:30:00    5
#2004-01-03 22:30:00    6
#Warning message:
#timezone of object (GMT) is different than current timezone ().

#So I am going to change the timezone in the system and see what happens
Sys.setenv(TZ=GMT)

y.1-xts(1:6,as.POSIXct(y,format=fmt,tz=GMT))
update(index(y.1),month=unique(month(index(x.1  
#[1] 2004-01-04 01:15:00 GMT 2004-01-04 01:30:00 GMT
#[3] 2004-01-04 01:45:00 GMT 2004-01-04 02:00:00 GMT
#[5] 2004-01-04 02:30:00 GMT 2004-01-04 03:30:00 GMT
 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


A.K.


From: Eric Morway emor...@usgs.gov
To: arun smartpink...@yahoo.com 
Cc: R help r-help@r-project.org 
Sent: Saturday, November 3, 2012 11:44 AM
Subject: Re: [R] override date in xts time series


Hello Arun,  

I too am using R 2.15 and am unable
to get the same result as you.  You will notice in the R code that
follows that when I use 'update' the time in the xts object goes haywire.
 For example, 2004-04-04
01:15:00 ESTgets converted
to 2004-01-03 22:15:00 PST(see below).  Because I can't get the result you 
showed me in your
previous response, and maybe you won't be able to get this result, I've
resorted back to your other suggestion using gsub.  I don't have a
good handle on regular expressions and was wondering if in the last line
of code below, the replace month is 'hardwired'?  In other words,
could \\101\\2somehow be replaced with unique(month(index(x.1)))in
the last line of code below so that x.1 is providing the replacement month,
rather than have it fixed?  Or perhaps I've misunderstood the regular
expression, which is entirely possible. 


sessionInfo() 
#R version 2.15.2 (2012-10-26) 
#Platform: x86_64-w64-mingw32/x64 (64-bit) 

library(xts) 
library(lubridate) 

x.Date - rep(1/1/2004,times=5) 
x.Times- c(01:15:00,
01:30:00, 01:45:00, 

     02:00:00, 02:30:00, 03:00:00,
03:15:00) 
x-paste(x.Date,x.Times) 

y.Date - rep(4/4/2004,times=4) 
y.Times- c(01:15:00,
01:30:00, 01:45:00, 

     02:00:00, 02:30:00, 03:30:00) 

y-paste(y.Date,y.Times) 

fmt - %m/%d/%Y %H:%M:%S 
x.1-xts(1:7, as.POSIXct(x, format=fmt,
tz = EST)) 
y.1-xts(1:6, as.POSIXct(y, format=fmt,
tz = EST)) 

y.1 

#          
         [,1] 
#2004-04-04 01:15:00    1 
#2004-04-04 01:30:00    2 
#2004-04-04 01:45:00    3 
#2004-04-04 02:00:00    4 
#2004-04-04 02:30:00    5 
#2004-04-04 03:30:00    6 
#Warning message: 
#timezone of object (EST) is different
than current timezone ().  

index(y.1) 
# 2004-04-04 01:15:00 EST
2004-04-04 01:30:00 EST 
# 2004-04-04 01:45:00 EST
2004-04-04 02:00:00 EST 
# 2004-04-04 02:30:00 EST
2004-04-04 03:30:00 EST 

index(y.1)-update(index(y.1),month=unique(month(index(x.1  
index(y.1) 

# 2004-01-03 22:15:00 PST
2004-01-03 22:30:00 PST 
# 2004-01-03 22:45:00 PST
2004-01-03 23:00:00 PST 
# 2004-01-03 23:30:00 PST
2004-01-04 00:30:00 PST 


index(y.1)-as.POSIXct(gsub((.*\\-).*(\\-.*),\\101\\2,index(y.1)))          
         

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained

Re: [R] override date in xts time series

2012-11-02 Thread arun
HI,
You can use:
library(lubridate)
index(y.1)-update(index(y.1),month=1)
#or
index(y.1)-update(index(y.1),month=unique(month(index(x.1


 y.1
    [,1]
#2004-01-01 00:00:00    1
#2004-01-01 00:15:00    2
#2004-01-01 00:45:00    3
#2004-01-01 01:00:00    4
A.K.





- Original Message -
From: Eric Morway emor...@usgs.gov
To: r-help@r-project.org
Cc: 
Sent: Friday, November 2, 2012 7:55 AM
Subject: [R] override date in xts time series


   Using  the  following  bit  of  R,  I'm wondering if there is a way to
   override/manipulate/replace the date in one xts time series with the date of
   another xts time series while not affecting/changing the times of the xts
   time series?

   library(xts)
   x.Date - rep(1/1/2004,times=5)
   x.Times- c(00:00:00, 00:15:00, 00:30:00,
                  00:45:00, 01:00:00)
   x-paste(x.Date,x.Times)
   y.Date - rep(3/1/2004,times=4)
   y.Times- c(00:00:00, 00:15:00,
                  00:45:00, 01:00:00)
   y-paste(y.Date,y.Times)
   fmt - %m/%d/%Y %H:%M:%S
   x.1-xts(1:5, as.POSIXct(x, format=fmt))
   y.1-xts(1:4, as.POSIXct(y, format=fmt))

   If possible, I'd like query the date of x.1 and use it to override the date
   in y.1, leaving the times as they are.  So the current output looks like
   this:

   x.1
   #                    [,1]
   #2004-01-01 00:00:00    1
   #2004-01-01 00:15:00    2
   #2004-01-01 00:30:00    3
   #2004-01-01 00:45:00    4
   #2004-01-01 01:00:00    5
   y.1
   #                    [,1]
   #2004-03-01 00:00:00    1
   #2004-03-01 00:15:00    2
   #2004-03-01 00:45:00    3
   #2004-03-01 01:00:00    4
   But I would like change y.1 to look like the following by using the date of
   x.1 (notice the month was updated to match x.1):
   y.1
                       [,1]
   2004-01-01 00:00:00    1
   2004-01-01 00:15:00    2
   2004-01-01 00:45:00    3
   2004-01-01 01:00:00    4
   Thanks, Eric
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] override date in xts time series

2012-11-02 Thread arun
Hi,
If you don't want to use library(lubridate):

This should also work.
 index(y.1)-as.POSIXct(gsub((.*\\-).*(\\-.*),\\101\\2,index(y.1)))
 y.1
#    [,1]
#2004-01-01 00:00:00    1
#2004-01-01 00:15:00    2
#2004-01-01 00:45:00    3
#2004-01-01 01:00:00    4
A.K.




- Original Message -
From: Eric Morway emor...@usgs.gov
To: r-help@r-project.org
Cc: 
Sent: Friday, November 2, 2012 7:55 AM
Subject: [R] override date in xts time series


   Using  the  following  bit  of  R,  I'm wondering if there is a way to
   override/manipulate/replace the date in one xts time series with the date of
   another xts time series while not affecting/changing the times of the xts
   time series?

   library(xts)
   x.Date - rep(1/1/2004,times=5)
   x.Times- c(00:00:00, 00:15:00, 00:30:00,
                  00:45:00, 01:00:00)
   x-paste(x.Date,x.Times)
   y.Date - rep(3/1/2004,times=4)
   y.Times- c(00:00:00, 00:15:00,
                  00:45:00, 01:00:00)
   y-paste(y.Date,y.Times)
   fmt - %m/%d/%Y %H:%M:%S
   x.1-xts(1:5, as.POSIXct(x, format=fmt))
   y.1-xts(1:4, as.POSIXct(y, format=fmt))

   If possible, I'd like query the date of x.1 and use it to override the date
   in y.1, leaving the times as they are.  So the current output looks like
   this:

   x.1
   #                    [,1]
   #2004-01-01 00:00:00    1
   #2004-01-01 00:15:00    2
   #2004-01-01 00:30:00    3
   #2004-01-01 00:45:00    4
   #2004-01-01 01:00:00    5
   y.1
   #                    [,1]
   #2004-03-01 00:00:00    1
   #2004-03-01 00:15:00    2
   #2004-03-01 00:45:00    3
   #2004-03-01 01:00:00    4
   But I would like change y.1 to look like the following by using the date of
   x.1 (notice the month was updated to match x.1):
   y.1
                       [,1]
   2004-01-01 00:00:00    1
   2004-01-01 00:15:00    2
   2004-01-01 00:45:00    3
   2004-01-01 01:00:00    4
   Thanks, Eric
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] override date in xts time series

2012-11-02 Thread Eric Morway
Hello Arun, 

My earlier example was not very robust.  It seems issues arise during DST:

library(xts)
library(lubridate)

x.Date - rep(1/1/2004,times=5)
x.Times- c(01:15:00, 01:30:00, 01:45:00,
   02:00:00, 02:30:00, 03:00:00, 03:15:00)
x-paste(x.Date,x.Times)

y.Date - rep(4/4/2004,times=4)
y.Times- c(01:15:00, 01:30:00, 01:45:00,
   02:00:00, 02:30:00, 03:30:00)

y-paste(y.Date,y.Times)

fmt - %m/%d/%Y %H:%M:%S
x.1-xts(1:7, as.POSIXct(x, format=fmt))
y.1-xts(1:6, as.POSIXct(y, format=fmt))

index(y.1)-update(index(y.1),month=unique(month(index(x.1

y.1
#   [,1]
#2004-01-04 01:15:001
#2004-01-04 01:30:002
#2004-01-04 01:45:003
#NA   4
#NA   5
#2004-01-04 03:30:006

So, I'm wondering if there are built in functions/commands for dealing 
with this?  The code here is a smaller example of a larger problem I'm 
working on.  In the larger problem, the 'update' command you provided me 
with isn't updating, nor is it throwing an error.  I'm wondering if its 
related to DST?  Here is some example R output from the larger problem 
highlighting the behavior:

xs[[i]][2:3]
#  xQ  xSC
#2004-01-01 00:15:00 0.43   NA
#2004-01-01 00:30:00 0.43 2240

xs[[j]][2:3]
# xQ  xSC
#2004-04-04 00:15:00 669   NA
#2004-04-04 00:30:00 664 2320

The next line of code shows that the update command is return the desired 
result: 

update(index(xs[[j]][2:3]),month=unique(month(index(xs[[i]][2:3]
# 2004-01-04 00:15:00 PST 2004-01-04 00:30:00 PST

The next line shows what the current index is: 

index(xs[[j]][2:3])
# 2004-04-04 00:15:00 PST 2004-04-04 00:30:00 PST

Now I try running the code you showed me 

index(xs[[j]][2:3])-update(index(xs[[j]][2:3]),month=unique(month(index(xs[[i]][2:3]
#Warning message:
#In NextMethod(.Generic) :
# number of items to replace is not a multiple of replacement length

While there was a warning, there was no error, so I'm surprised that the 
index wasn't updated? 

xs[[j]][2:3]
# xQ  xSC
#2004-04-04 00:15:00 669   NA
#2004-04-04 00:30:00 664 2320

If its not day light savings, do you have any other thoughts as to what 
the problem might be? 





From:
arun smartpink...@yahoo.com
To:
Eric Morway emor...@usgs.gov
Cc:
R help r-help@r-project.org
Date:
11/02/2012 06:22 AM
Subject:
Re: [R] override date in xts time series



HI,
You can use:
library(lubridate)
index(y.1)-update(index(y.1),month=1)
#or
index(y.1)-update(index(y.1),month=unique(month(index(x.1


 y.1
[,1]
#2004-01-01 00:00:001
#2004-01-01 00:15:002
#2004-01-01 00:45:003
#2004-01-01 01:00:004
A.K.





- Original Message -
From: Eric Morway emor...@usgs.gov
To: r-help@r-project.org
Cc: 
Sent: Friday, November 2, 2012 7:55 AM
Subject: [R] override date in xts time series


   Using  the  following  bit  of  R,  I'm wondering if there is a way to
   override/manipulate/replace the date in one xts time series with the 
date of
   another xts time series while not affecting/changing the times of the 
xts
   time series?

   library(xts)
   x.Date - rep(1/1/2004,times=5)
   x.Times- c(00:00:00, 00:15:00, 00:30:00,
  00:45:00, 01:00:00)
   x-paste(x.Date,x.Times)
   y.Date - rep(3/1/2004,times=4)
   y.Times- c(00:00:00, 00:15:00,
  00:45:00, 01:00:00)
   y-paste(y.Date,y.Times)
   fmt - %m/%d/%Y %H:%M:%S
   x.1-xts(1:5, as.POSIXct(x, format=fmt))
   y.1-xts(1:4, as.POSIXct(y, format=fmt))

   If possible, I'd like query the date of x.1 and use it to override the 
date
   in y.1, leaving the times as they are.  So the current output looks 
like
   this:

   x.1
   #[,1]
   #2004-01-01 00:00:001
   #2004-01-01 00:15:002
   #2004-01-01 00:30:003
   #2004-01-01 00:45:004
   #2004-01-01 01:00:005
   y.1
   #[,1]
   #2004-03-01 00:00:001
   #2004-03-01 00:15:002
   #2004-03-01 00:45:003
   #2004-03-01 01:00:004
   But I would like change y.1 to look like the following by using the 
date of
   x.1 (notice the month was updated to match x.1):
   y.1
   [,1]
   2004-01-01 00:00:001
   2004-01-01 00:15:002
   2004-01-01 00:45:003
   2004-01-01 01:00:004
   Thanks, Eric
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] override date in xts time series

2012-11-02 Thread arun
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.








From: Eric Morway emor...@usgs.gov
To: arun smartpink...@yahoo.com 
Cc: R help r-help@r-project.org 
Sent: Friday, November 2, 2012 8:52 PM
Subject: Re: [R] override date in xts time series


Hello Arun,  

My earlier example was not very robust.
 It seems issues arise during DST: 

library(xts) 
library(lubridate) 

x.Date - rep(1/1/2004,times=5) 
x.Times- c(01:15:00,
01:30:00, 01:45:00, 

     02:00:00, 02:30:00, 03:00:00,
03:15:00) 
x-paste(x.Date,x.Times) 

y.Date - rep(4/4/2004,times=4) 
y.Times- c(01:15:00,
01:30:00, 01:45:00, 

     02:00:00, 02:30:00, 03:30:00) 

y-paste(y.Date,y.Times) 

fmt - %m/%d/%Y %H:%M:%S 
x.1-xts(1:7, as.POSIXct(x, format=fmt)) 
y.1-xts(1:6, as.POSIXct(y, format=fmt)) 

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 
#NA        
          4 
#NA        
          5 
#2004-01-04 03:30:00    6 

So, I'm wondering if there are built
in functions/commands for dealing with this?  The code here is a smaller
example of a larger problem I'm working on.  In the larger problem,
the 'update' command you provided me with isn't updating, nor is it throwing
an error.  I'm wondering if its related to DST?  Here is some
example R output from the larger problem highlighting the behavior: 

xs[[i]][2:3] 
#          
           xQ  xSC 
#2004-01-01 00:15:00 0.43   NA 
#2004-01-01 00:30:00 0.43 2240 

xs[[j]][2:3] 
#          
          xQ  xSC 
#2004-04-04 00:15:00 669   NA 
#2004-04-04 00:30:00 664 2320 

The next line of code shows that the
update command is return the desired result:  

update(index(xs[[j]][2:3]),month=unique(month(index(xs[[i]][2:3] 
# 2004-01-04 00:15:00 PST
2004-01-04 00:30:00 PST 

The next line shows what the current
index is:  

index(xs[[j]][2:3]) 
# 2004-04-04 00:15:00 PST
2004-04-04 00:30:00 PST 

Now I try running the code you showed
me  

index(xs[[j]][2:3])-update(index(xs[[j]][2:3]),month=unique(month(index(xs[[i]][2:3]
 
#Warning message: 
#In NextMethod(.Generic) : 
# number of items to replace is not
a multiple of replacement length 

While there was a warning, there was
no error, so I'm surprised that the index wasn't updated?  

xs[[j]][2:3] 
#          
          xQ  xSC 
#2004-04-04 00:15:00 669   NA 
#2004-04-04 00:30:00 664 2320 

If its not day light savings, do you
have any other thoughts as to what the problem might be?  





From:  arun smartpink...@yahoo.com  
To:  Eric Morway emor...@usgs.gov  
Cc:  R help r-help@r-project.org  
Date:  11/02/2012 06:22 AM  
Subject:  Re: [R] override date in xts time series 




HI,
You can use:
library(lubridate)
index(y.1)-update(index(y.1),month=1)
#or
index(y.1)-update(index(y.1),month=unique(month(index(x.1


 y.1

[,1]
#2004-01-01 00:00:00    1
#2004-01-01 00:15:00    2
#2004-01-01 00:45:00    3
#2004-01-01 01:00:00    4
A.K.





- Original Message -
From: Eric Morway emor...@usgs.gov
To: r-help@r-project.org
Cc: 
Sent: Friday, November 2, 2012 7:55 AM
Subject: [R] override date in xts time series


   Using  the  following  bit  of  R, 
I'm wondering if there is a way to
   override/manipulate/replace the date in one xts time series