I have a very large timeseries(xts) data frame variables (>10) with varying number of rows,days and starting and ending dates. I want to combine these dataframe as a single time series dataframe.
For clarity I would give an example; consider A, B and C time series data frame with 100,200 and 300 rows of dates respectively and one column for its corresponding values.
A Result B Result C Result
2014-02-01 0.8478517865 2016-03-01 0.794655429 2014-02-01 0.5961746441
2015-03-02 0.8310818302 2016-03-02 0.4288015561 2014-08-03 0.4332428675
2015-04-13 0.6525838461 2016-03-04 0.8032966915 2015-03-01 0.4675749368
2015-04-27 0.0078298878 2016-03-06 0.588762206 2015-03-02 0.6404606516
2015-05-05 0.4810352649 2016-03-08 0.8551481313 2016-03-01 0.403449801
2015-05-06 0.2730398192 2016-03-10 0.7437164122 2016-03-09 0.1844344875
2015-05-07 0.5594211367 2016-03-11 0.1973790985
2015-05-08 0.1888440552 2016-03-13 0.5973634648
2015-05-09 0.8211225735
2015-05-10 0.2937804316
2015-05-11 0.4311328372
How can I combine these three time series data frames with one columns as a single data frame with 3 columns?
I have tried to use cbind(A,B) but its giving thise error
Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows:
Also tried this answer using rbind.fill(A,B) but its appending the time series data frame
row of A=100 with one column
row of B=200 with one column
after rbind.fill number of rows 300 column 1
Edited
This code is obtained from this answer.
cbind.fill <- function(...){
nm <- list(...)
nm <- lapply(nm, as.matrix)
n <- max(sapply(nm, nrow))
do.call(cbind, lapply(nm, function (x)
rbind(x, matrix(, n-nrow(x), ncol(x)))))
}
This function combines two xts dataframe but it doesn't do a proper alignment of data with dates
comb-cbind.fill(A,B)
head(comb)
1998-01-02 "0.332" "0.849"
1998-01-05 "0.227" "0.060"
1998-01-06 "0.394" "0.071"
1998-01-07 "0.422" "6.066"
tail(comb)
NA "0.306"
NA "0.479"
NA "0.127"
NA "0.321"
merge(A, B, C)
. – Joshua UlrichA<-Cl(aapl), B<-Cl(goog), C<-Cl(f), D..
– Eka