[R] match matrices of different lengths

Thijs vanden Bergh bergh.thijsvanden at gmail.com
Thu Jan 5 14:51:33 CET 2012


was trying to match different matrices of different lengths with in
the first collumn date and time info (yearmonthdayhourminute). the
routine needs to return NA´s where data  of either of the matrices is
non existent.

have been trying the following:

####
x <- c(200112030003, 200112030004, 200112030005, 200112030006)
y <- c(0.1, 1, 1.1, 1.5)
a <- c(200112030004, 200112030005, 200112030007, 200112030008, 200112030009)
b <- c(1.2, 1.9, 2.0, 2.5, 2.1)

xx <- cbind(x, y)
aa <- cbind(a, b)

xxnew <- ts(xx)
aanew <- ts(aa)

cc <- ts.union(xxnew, aanew)
cc
####

this does however not give the wished for result as it simply cbinds
the two matrices and filles up empty spots that are created due to the
one matrix being shorter then the other at the bottom end of the
shortest matrix. i realy want the routine to match matrix xx and aa
to time in the first collumn of both matrices.

any help towards this end would be much appreciated,

th.



More information about the R-help mailing list