[R] [R-SIG-Finance] Creating regularly spaced time series from irregular one

Gabor Grothendieck ggrothendieck at gmail.com
Tue Feb 23 01:17:51 CET 2010

You probably want to ask the author of the its package directly about that.

Note that as.zoo has an its method and as.its has a zoo method and
they will allow you to convert back and forth between its and zoo so
you can effectively use the functionality of both packages:

# converting back and forth
ii <- its(1:3, seq(Sys.time(), length = 3, by = "day"))
z <- as.zoo(ii)
ii2 <- as.its(z)

In zoo, see the discussion of the intraday.discretize function which
is defined in the following vignette:


# also see

The discretizing discussion mentioned may apply in concept if not
literally to its as well.

Also note that zoo has an its method for the lattice xyplot function.

The xts package is defined as a layer on top of zoo and shares some
functions and methods with zoo and is particularly geared to finance
along with the quantmod package by the same author so see them too.
Also there is a list of R packages in the zoo-faq vignette mentioned
above that may be of interest.

On Mon, Feb 22, 2010 at 3:52 PM, Ivan Kalafatic
<ivan.kalafatic at gmail.com> wrote:
> Hello,
> I have a series of intraday (high-frequency) price data in the form of POSIX
> timestamp followed by the value.
> I sucesfuly loaded that into "its" package object. I would like to create
> from it a regularly spaced time series of prices (for example 1min, 5min,
> etc apart) so i could calcualte returns.
> There is an interpolation function locf() that for timestamp with value NA
> uses last known observation.
> I guess the idea would be to start from the begining of my series and, for
> example, if there is no timestamp for t+5min add that time with value NA.
> Than I could use locf() function to fill those NAs. Finaly I should extract
> from that series, series with 5min spaced timestamps with prices.
> Appart from applying locf() function, I have no idea how to add NAs into
> original series or extract the regular series after.
> Can someone help me with this?
> Thank you.

More information about the R-help mailing list