[R] Quick question on merging two time-series of different frequencies
Achim Zeileis
Achim.Zeileis at wu-wien.ac.at
Thu May 10 19:11:44 CEST 2007
On Thu, 10 May 2007, Patnaik, Tirthankar wrote:
> Hi,
> A quick beginner's question. I have two time series, A with
> daily data, and another B with data at varying frequencies, but mostly
> annual. Both the series are sorted ascending.
>
> I need to merge these two series together in the following way: For any
> entry of A, the lookup should match with B until we find an entry of B
> that's larger than A's.
I'm not sure what exactly you want. I assume that A and B are not the
observations but the corresponding time stamps, right?
In any case, I guess that the "zoo" package will have some useful
functionality for what you want, e.g., if you have data like
library("zoo")
set.seed(123)
x <- zoo(rnorm(11), as.Date("2000-01-01") + 0:10)
y <- zoo(rnorm(4), as.Date("2000-01-01") + c(0, 3, 7, 10))
then you can merge them with
z <- merge(x, y)
and then eliminate NAs, e.g. by
na.locf(z)
or you could aggregate() the "x" series so that it becomes a monthly
series or something like that.
See
vignette("zoo", package = "zoo")
for more information.
Best,
Z
> For all A[i], i = 1,...,N and B[j], j=1,...M
>
> Match with B[j] where A[i] <= B[j]
>
> When A[i] > B[j], match with B[j+1] where A[i] <= B[j+1]
>
> Basically the less-frequent attributes stay true for a stock while the
> daily prices change.
>
> One example of this is the vlookup function in Excel with the TRUE
> option.
>
> So we have an implementation of this in R?
>
> TIA and best,
> -Tir
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
More information about the R-help
mailing list