Re: [R] An entire data frame which is a time-series?

2004-08-17 Thread Gabor Grothendieck
Ajay Shah  mayin.org> writes:

: 
: I have :
: 
: raw <- read.table("monthly.text", skip=3, sep="|",
: col.names=c("junk", "junk2",
:   "wpi", "g.wpi", "wpi.primary", "g.wpi.primary",
:   "wpi.fuel", "g.wpi.fuel", "wpi.manuf", "g.wpi.manuf",
:   "cpi.iw", "g.cpi.iw", "cpi.unme", "g.cpi.unme",
:   "cpi.al", "g.cpi.al", "cpi.rl", "g.cpi.rl"))
: 
: Now I can do things like:
: 
:   g.wpi = ts(raw$g.wpi, frequency=12, start=c(1994,7))
: 
: and it works fine. One by one, I can make time-series objects.
: 
: Is there a way to tell R that the entire data frame is a set of
: time-series, so that I don't have to go column by column and make a
: new ts() out of each?
: 
: I tried:
: 
:   M = ts(raw, frequency=12, start=c(1994,7))
:   ts.plot(M[,"wpi"], M[,"wpi.manuf"])
: 
: but this gives nonsense results. 

Converting a data frame to a ts object seems to work for me:

R> my.df <- data.frame(a = 1:4, b = 5:8)
R> my.ts <- ts(my.df, start=c(2000,4), freq=12)
R> my.ts.a <- my.ts[,"a"]
R> my.ts.a
 Apr May Jun Jul
2000   1   2   3   4

Suggest you provide a small reproduceable example that illustrates
the problem.


: Also, syntax like M$wpi is a lot
: nicer than M[,"wpi"]. Any ideas about what might work?

R> "$.ts" <- function(x, i) x[,i]
R> my.ts$a
 Apr May Jun Jul
2000   1   2   3   4

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] An entire data frame which is a time-series?

2004-08-17 Thread Ajay Shah
I have :

raw <- read.table("monthly.text", skip=3, sep="|",
col.names=c("junk", "junk2",
  "wpi", "g.wpi", "wpi.primary", "g.wpi.primary",
  "wpi.fuel", "g.wpi.fuel", "wpi.manuf", "g.wpi.manuf",
  "cpi.iw", "g.cpi.iw", "cpi.unme", "g.cpi.unme",
  "cpi.al", "g.cpi.al", "cpi.rl", "g.cpi.rl"))

Now I can do things like:

  g.wpi = ts(raw$g.wpi, frequency=12, start=c(1994,7))

and it works fine. One by one, I can make time-series objects.

Is there a way to tell R that the entire data frame is a set of
time-series, so that I don't have to go column by column and make a
new ts() out of each?

I tried:

  M = ts(raw, frequency=12, start=c(1994,7))
  ts.plot(M[,"wpi"], M[,"wpi.manuf"])

but this gives nonsense results. Also, syntax like M$wpi is a lot
nicer than M[,"wpi"]. Any ideas about what might work?


An unrelated suggestion: I found the documentation of ts() to be quite
daunting. I have been around time-series and computer programming for
decades. But it took me a while to handle the basics : to read in a
file, to make time-series vectors, to run ARMA models. This stuff
ought to be easier to learn. I tried to write an ARMA example, and put
it up on the web, which would've been a godsend to me if I had found
it earlier (http://www.mayin.org/~ajayshah/KB/R/tsa.html).

I believe that the R documentation framework could do well by always
having a 2000 word conceptual introduction + little tutorial on each
package, instead of straight jumping into man pages on each function
(which is the only documentation that we have presently).

-- 
Ajay Shah   Consultant
[EMAIL PROTECTED]  Department of Economic Affairs
http://www.mayin.org/ajayshah   Ministry of Finance, New Delhi

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html