## TemporalData frequency option as in R

9

2

I'm studying R, and am very impressed by the simplicity of some commands and in the way R handles temporal data. For example, in R, if you have some one-dimensional temporal data, you can easily transform it into a data series using:

url<-"http://www.massey.ac.nz/~pscowper/ts/cbe.dat"
timeSeriesCol1=ts(data[,1],start=1958,frequency=12)

In Mathematica, we have the new TemporalData function, but to do the same as in R, the code is a little clumsy due to the lack of frequency option or an equivalent. See the code:

url="http://www.massey.ac.nz/~pscowper/ts/cbe.dat";
data=Import[url];
timeSeriesCol1=TemporalData[Rest@data[[All,1]],{{1958,1},DatePlus[{1958,1},{Length[data],"Month"}]}]
DateListPlot[N@timeSeriesCol1["Path"]]

The part {{1958,1},DatePlus[{1958,1},{Length[CBE],"Month"}]} is very inelegant and DateListPlot does not directly recognize the object (and you need to convert it to a number, which look likes a bug).

Does anyone have a clue for a more elegant way to handle this using TemporalData?

13

The following seems a little more elegant.

data = Import["http://www.massey.ac.nz/~pscowper/ts/cbe.dat"];

ts = TemporalData[data[[2 ;; -1, 1]], {"1958", Automatic, "Month"}];

DateListPlot[ts["Path"]]

TemporalData can also store multiple paths.

ts2= TemporalData[Transpose[data[[2 ;; -1]]], {"1958", Automatic, "Month"}];

DateListPlot[ts2["Paths"]]

much better. Tks! – Murta – 2012-12-20T10:28:41.130