[R] Multiple time series and their names

Gabor Grothendieck ggrothendieck at gmail.com
Sat Oct 3 05:34:49 CEST 2009


zoo objects can have one column with a heading and convert back
faithfully to ts:

> library(zoo)
> as.zoo(x)[, 1, drop = FALSE]
            Juan
1(1) -0.37415224
1(2) -0.30875111
1(3) -0.02617545
1(4) -0.45053564
2(1)  0.15173749
2(2)  1.38545761
2(3)  2.11594058
2(4) -0.84970010
3(1) -0.05944844
3(2)  1.27543030
> tsp(x)
[1] 1.00 3.25 4.00
> tsp(as.ts(as.zoo(x)))
[1] 1.00 3.25 4.00


On Fri, Oct 2, 2009 at 11:15 PM, David Stoffer <dsstoffer at gmail.com> wrote:
>
> Suppose I have multiple time series with names for each one, for example,
>
> x <- ts(matrix(rnorm(30,0,1),10,3), names=c("Juan", "Tuey", "Trey"),
> frequency=4)
>
> So now, as I start to explore these series, if I do everything at once, the
> names
> stay attached to the series.  For example,
> plot(x) # gives a plot of the series with their names
> acf(x)  # gives the ACFs & CCFs with names attached
>
> But if I want to explore what's going on with Juan, from what I can gather,
> I have to do something like this
> plot(x[,1])
> (or acf(x[,1])... or similar things) but this doesn't keep the name Juan.
>
> My question: Is there a way, without making a data frame [which seems to
> destroy the
> time series attributes(??) - this seems to be the only answer I can find on
> Rhelp]
> that allows me to keep track of the names?  That way, for example, I don't
> have to
> remember that the 18th series is Martha.
>
> x$Juan, x$Tuey, x$Trey, would be nice ... but that doesn't work.
>
> Thanks in advance.
>
>
> -----
> The power of accurate observation is commonly called cynicism
> by those who have not got it.  George Bernard Shaw
> --
> View this message in context: http://www.nabble.com/Multiple-time-series-and-their-names-tp25725411p25725411.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list