Question

I have two xts objects as:

buypoints
2010-04-20 7.096034  
2010-04-22 7.097276  
2010-06-02 7.001592  
2010-06-10 6.991030  
2010-07-09 6.982826  
2010-08-27 6.970345



sell points  
2010-04-16 7.083497  
2010-04-21 7.095015  
2010-04-27 7.076409  
2010-06-04 6.970617  
2010-06-24 6.978857  
2010-08-05 7.026258  
2010-09-27 7.040676  
2010-10-28 7.076468

I want to merge both these objects,so that my final output looks like:

2010-04-16 7.083497  
2010-04-20 7.096034   
2010-04-21 7.095015  
2010-04-22 7.097276   
2010-04-27 7.076409  
2010-06-02 7.001592   
2010-06-04 6.970617  
2010-06-10 6.991030    
2010-06-24 6.978857  
2010-07-09 6.982826    
2010-08-05 7.026258  
2010-08-27 6.970345    
2010-09-27 7.040676  
2010-10-28 7.076468

That is,the data from both objects are arranged in chronological order in one column only. Please suggest a method of doing so

Was it helpful?

Solution

You might try something like:

rbind(buypoints, sellpoints)
# [,1]
# 2010-04-16 7.083497
# 2010-04-20 7.096034
# 2010-04-21 7.095015
# 2010-04-22 7.097276
# 2010-04-27 7.076409
# 2010-06-02 7.001592
# 2010-06-04 6.970617
# 2010-06-10 6.991030
# 2010-06-24 6.978857
# 2010-07-09 6.982826
# 2010-08-05 7.026258
# 2010-08-27 6.970345
# 2010-09-27 7.040676
# 2010-10-28 7.076468
# > class(rbind(buypoints, sellpoints))
# [1] "xts" "zoo"

It looks as though xts has forseen your need to sort by date, thus obviating any explicit sort function here. Pretty neat, eh?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top