Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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"
data<-read.table(url,header=T)
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?

share|improve this question
add comment

1 Answer

up vote 13 down vote accepted

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"]]

enter image description here

TemporalData can also store multiple paths.

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

DateListPlot[ts2["Paths"]]

enter image description here

share|improve this answer
    
much better. Tks! –  Murta Dec 20 '12 at 10:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.