[R] time series missing 0 counts
Dirk Eddelbuettel
edd at debian.org
Sat Feb 15 06:17:00 CET 2003
On Fri, Feb 14, 2003 at 11:21:33AM +0000, ripley at stats.ox.ac.uk wrote:
> Yes, there is an easy way. Create the regular time series you want by
> something like
>
> x <- ts(0, start=c(2000,52), end=c(2003,9), frequency=52)
>
> and fill in the time points you have data for by
>
> xYear <- trunc(times(x)); xWeek <- cycle(x)
> attach(mydata)
> x[(xYear==year) & (xWeek==Week)] <- Count
> detach()
But won't this will fail for weeks with a count number of 0 or 53 (as both
of those are outside the ts() range specified above)?
As 52*7=364 is different from the number of days in a year, each year is
bound to have one of those unless the data is pre-scrubbed.
Dirk
> Easy!
>
> On Fri, 14 Feb 2003, Schnitzler, Johannes wrote:
>
> > > I have several large data sets with counts per week.
> > > (Maximum week per year is 52. Counts from Week 53
> > > are added to week 52.)
> > >
> > > A data set contains for example:
> > >
> > > Year Week Count
> > > 2000 52 2
> > > 2001 1 5
> > > 2001 2 7
> > > 2001 5 4
> > > 2001 7 2
> > > ... ... ...
> > > ... ... ...
> > >
> > > Weeks with 0 counts are not listed in the data set.
> > > I want to perform time series analysis (frequency 52).
> > >
> > >
> > > Is there an easy way to expand the data set to:
> > >
> > > Year Week Count
> > > 2000 52 2
> > > 2001 1 5
> > > 2001 2 7
> > > 2001 3 0
> > > 2001 4 0
> > > 2001 5 4
> > > 2001 6 0
> > > 2001 7 2
> > > ... ... ...
> > > ... ... ...
> > >
> > > or is there already a function in "ts", which i have not found so far,
> > > to deal with this problem?
> > >
> > >
> > > Thank you very much.
> > >
> > > Johannes Schnitzler
> > > Germany Berlin
> > >
> > >
> > >
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > http://www.stat.math.ethz.ch/mailman/listinfo/r-help
> >
>
> --
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
--
Prediction is very difficult, especially about the future.
-- Niels Bohr
More information about the R-help
mailing list