[R] TS data frames

Dirk Eddelbuettel edd at debian.org
Sun May 18 19:56:25 CEST 2003


On Sun, May 18, 2003 at 02:21:08PM -0400, Welch, Ivo wrote:
> 
> hi chaps:  apologies, more naive beginner's questions.  my data sets 
> contain multiple time series and look like
> 
> date   x   y
> 196211   12   1
> 196212   4   2
> 196301   44   5
> 
> so dataset <- read.table("data.dat", header=T); works well enough.  
> tsdataset<- ts(dataset, freq=12, start=c(1962,11))  also seems to work.  
> summary(tsdataset) and print(tsdataset) show that this operation did 
> what I intended. 
> 
> * Alas, tsdataset$x no longer works.  how do I specify data series 
> inside tsdataset now?

tsdataset[,"x"]

> * Is there a time-series equivalent of read.table(), preferably allowing 
> me to specify that the data column is the appropriate data in yyyymm format?

No, just write yourself a simple wrapper doing read.table() and then ts()
creation.

> * For arguments sake, let's assume I want to do something with every 
> variable in my data set.  for example, I want to convert every single 
> data series into a time series.  "for (a in names(dataset)) a<-ts(a)" of 
> course does not do what I want, because the destination is a vector 
> named a, not a vector named by the contents of a.  I need sort of an 
> eval.  similarly "for (a in names(dataset)) a<- uppercase-name(a)".   
> Generically, how do I do something with every single series in a data 
> set, and then assign it back to replace the old series within the data set?

I am sure there are more elegant ways to do it, I typically just assign to
list elements:

for (i in 1:length(names(dataset)))
  a[[i]] <- ts(dataset[i])

> * unrelated:  are there a push, pop, shift functions for vectors, ala perl?

AFAIK not in base, you could emulate it, though. I needed something similar
recently and just hid it inside a list, and in- and decremented a hidden
index counter.

> * unrelated:  summary(vector) gives information in a row.  
> summary(dataset) gives information in blocks.  can it be instructed to 
> give information in rows, too?  where would I find documentation on 
> issues like this?

How about the code?  Requires some familiarity with the S language, though.

> sorry for all these questions.  help appreciated.

My pleasure. Always nice to see other financial economists around here :)

Regards,  Dirk

-- 
Don't drink and derive. Alcohol and analysis don't mix.




More information about the R-help mailing list