# [R] Multiple time series and their names

David Stoffer dsstoffer at gmail.com
Sat Oct 3 19:37:20 CEST 2009

```That info along with drop=FALSE seems to be a reasonable hack.

Thanks again-
David

Gabor Grothendieck wrote:
>
> You can use names using your example ts series like this
>
>  x[, "Juan"]
>
>
> On Sat, Oct 3, 2009 at 11:04 AM, David Stoffer <dsstoffer at gmail.com>
> wrote:
>>
>> Thanks for the help.  My basic problem is that I have given my series
>> names,
>> but I still have to call them number 1, 2, and so on, to do things with
>> them.  If I want to compare "GNP" with "Private Investment", I have to
>> remember which columns contains those series.
>>
>> The concern I have is that I'm giving these data sets to other people.
>> Now,
>> if give someone a data frame, I can ask them to compare John with Martha
>> without them having to know (or remember) that John's data are in column
>> 93
>> and Martha's are in column 22.  I'd like to do the same thing with a time
>> series matrix.
>>
>>
>> David
>>
>>
>>
>> Gabor Grothendieck wrote:
>>>
>>> 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.
>>>>
>>>>
>>>>
>>>> -----
>>>> 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
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
>>
>> -----
>> 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-tp25725411p25729650.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
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

-----
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-tp25725411p25730984.html
Sent from the R help mailing list archive at Nabble.com.

```