[R] seriesMerge

Gabor Grothendieck ggrothendieck at myway.com
Thu Nov 25 04:50:28 CET 2004


Yasser El-Zein <abu3ammar <at> gmail.com> writes:

: 
: Is there a function in R that is equivalent to S-PLUS's 
: seriesMerge(x1, x2, pos="union")
: where x1, and x2 are of class timeSeries
: 
: seriesMerge is in S-PLUS's finmetrics. I looked into R's mergeSeries
: (in fSeries part of Rmetrics) but I could not make it behave quite the
: same. In R it expected a timeSeries object and a matrix of the same
: row count. In S-PLUS when using the union option both objects can be
: of different lengths.

merge.zoo in package zoo handles union, intersection, left
and right join of unequal length time series according to the 
setting of the all= argument.  zoo can also work with chron dates 
and times which would allow you to work with your millisecond data
and can also merge more than two series at a time.   (The its 
package (see ?itsJoin) and for regular time series, cbind.ts, also 
support merging unequal length series but neither of these support 
chron which I gather is a requirement for you.)

eg. zoo example.
In the following x has  length 8 and y has length 6 and
they overlap for chron(5:8).  chron(1:4) only belongs
to x and chron(9:10) only belongs to y.

library(chron)
library(zoo)
x <- zoo(1:8, chron(1:8)) 
y <- zoo(5:10, chron(5:10))
merge(x,y) # union
merge(x,y,all=FALSE) # intersection
merge(x,y,all=c(FALSE, TRUE)) # right join
merge(x,y,all=c(TRUE, FALSE)) # left join




More information about the R-help mailing list