[R] daily time series in R
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Apr 30 18:50:03 CEST 2004
On Fri, 30 Apr 2004, John Muller wrote:
> I have some daily data and would like to apply some of the time series
> functions to it.
> I have read various notes in the help archive on this, the latest I found suggested
> that I need to use the irts class (Irregularly spaced time series) for daily data
> since a year does not divide into an integer number of days.
> I see why I would have to do that if I have gaps (e.g. only data on weekdays)
> but do I still have to do that even if I have no gaps, that is if I have every
> data for every day of the year? In the latter case, the data is evenly spaced,
> it;s just that a year is not an integer multiple of this spacing.
You can have daily or weekly data as a "ts" object, provided there are no
gaps. You can set the frequency to one if it suits you: the frequency
only affects the labelling (including of frequencies in spectral
The `time series functions' only apply to objects of class "ts", so you do
need to use that.
> I have the same question for weekly data
> (which I might create from daily data sampled only on work or weekdays)
> Here again, the data is sampled at regular intervals, but a year is not
> an integer multiple of the distance between samples.
> Can you give some suggestions for dealing with this?
> Should I first create an irts object and then create a ts from that?
> If that is the suggestion, then when I get a ts object I have noticed
> that in the plot the time axis has year and a decimal fraction of year.
> What's a good way to get more standard time increments on the X axis,
> such as months or week start days?
Add an axis yourself: see ?axis.POSIXct. R is programmable, and not
everyone's wishes are already programmed in.
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help