[R] Merge xts

Lily_stats sundusc at gmail.com
Tue Aug 17 11:10:01 CEST 2010


Hi all , 

I have 12 xts objects of differing timeseries stamp. For example : 

> str(s1_predict.xts)
An ‘xts’ object from 1990-03-25 20:00:00 to 1990-12-15 09:00:00 containing:
  Data: num [1:725, 1] 11.23 10.18 9.3 9.74 10.18 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : NULL
  Indexed by objects of class: [POSIXt,POSIXct] TZ: 
  Original class: 'double'  
  xts Attributes:  
 NULL

> str(s2_predict.xts)
An ‘xts’ object from 1990-03-26 22:00:00 to 1990-12-17 containing:
  Data: num [1:437, 1] 7.79 7.45 7.12 6.27 5.93 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : NULL
  Indexed by objects of class: [POSIXt,POSIXct] TZ: 
  Original class: 'double'  
  xts Attributes:  
 NULL

I would like to merge all the data onto one xts object. i.e./ put all the
time series in order and its corresponding data. I have tried several ways,
but it seems because my timestamps all differ, I am not able to use the
merge function. 

If I use the merge function it puts the time series together but the data
are all in differing columns, for example , 

>merge_1<-merge(s1_predict.xts,s2_predict.xts,s3_predict.xts)

1990-03-27 02:00:00       6.142707             NA             NA
1990-03-27 03:00:00       6.142707             NA             NA
1990-03-27 04:00:00             NA      6.2688687             NA
1990-03-27 05:00:00             NA      5.9300110             NA
1990-03-27 06:00:00             NA             NA      6.1398562
1990-03-27 07:00:00             NA             NA      5.3504461

Ideally, I would like this : 

1990-03-27 02:00:00       6.142707             
1990-03-27 03:00:00       6.142707             
1990-03-27 04:00:00       6.2688687             
1990-03-27 05:00:00       5.9300110             
1990-03-27 06:00:00       6.1398562
1990-03-27 07:00:00       5.3504461


Is there a smart way around this?

Thank you in advance.
-- 
View this message in context: http://r.789695.n4.nabble.com/Merge-xts-tp2327981p2327981.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list