Skip to content

Merge xts

1 message · Lily_stats

#
Hi all , 

I have 12 xts objects of differing timeseries stamp. For example :
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
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 ,
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.