[R] ts basic question
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Tue Aug 27 13:54:05 CEST 2002
On Tue, 27 Aug 2002, juli g. pausas wrote:
> Dear R collegues,
>
> I'd like to use the time-series facilities of R and I'm not sure how to
> set my dataset properly.
> I have monthly data, so the description could be: ts(data,
> start=c(1951,1), frequency= 12)
> However, the data is a matrix of years (rows) and months (columns), as
> follows:
>
> > s1 <- read.table("stdata.txt", header=TRUE)
> > s1[1:3, ]
> YEAR JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
> 1 1951 1.7 0.6 -0.8 -0.6 -1.0 -0.3 -1.4 -0.7 -1.3 -1.4 -1.0 -1.0
> 2 1952 -1.2 -1.1 0.0 -0.5 0.6 0.5 0.4 -0.4 -0.3 0.2 -0.2 -1.6
> 3 1953 0.2 -1.0 -0.8 -0.1 -2.2 -0.3 -0.1 -1.9 -1.5 -0.2 -0.4 -0.7
> >
>
> How can I create a ts object from this format?
Something like
ts(t(si), start=c(1951,1), frequency= 12)
since t will convert it to a matrix.
> Alternatively, I could delete the column YEAR from the file, read the
> file with scan to create a single vector (reading by rows), and then
> use: ts(s1, start=c(1951,1), frequency= 12).
> Is there a better way to do this?
Yes. Use skip in scan and don't alter the file.
--
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list