[R] ts basic question

juli g. pausas juli at ceam.es
Tue Aug 27 13:31:55 CEST 2002


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?
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?

Thanks in advance
(R 1.5.0)

Juli

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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