On Sun, 23 Dec 2001, Bill Vedder wrote:
>
> Happy Holidays All,
>
> I'm trying to use stl() to extract a seasonal component from a time
> series. I believe the root cause of my problem lies in how I imported
> the data into R.
>
> In Excel (csv), the data look like:
> Jan Feb Mar ....
> 1949 12.2 9.0 7.9 ....
> 1950 17.2 16.9 9.9 ....
> 1951 8.2 7.0 7.7 ....
>
> I import to R using:
> a<-read.csv("d:/programs/r/airpass.csv",header=TRUE, sep =
",")
>
> then I try to coerce a to a .ts object using:
> > a.ts<- as.ts(a)
>
> but get the following error:
> Error in dimnames<-.data.frame(*tmp*, value = list(NULL, names)) :
> invalid dimnames given for data frame
>
> I have tried everything (except what works). When I do:
>
> > mode(a)
>
> R returns:
> [1] "list"
>
> Other things I've done show me that R is treating the columns as
> separate variables.
>
> How do I specify to R that I want the csv data read as a single,
> univariate times series sampled once/month over many years?
With some difficulty! Try
a <- ts(as.vector(t(as.matrix(a))), start=c(1949, 1), freq = 12)
That takes the data frame, makes a matrix, reads it by row and turns it
into a time series (if I got it right).
--
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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._