[R] ts.intersect a multivariate and univariate ts

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Jun 5 09:48:07 CEST 2005


some_df[1, ] is actually a data frame: see ?"[.data.frame".  It's hard to 
see what else it could be, as columns of a data frame are of arbitrary 
classes.

When you apply matrix() to a data frame it gets dropped to a list.


On Sat, 4 Jun 2005, Andy Bunn wrote:

> Adam:
>> Providing a reproducible example would be a first step...
>
> That's the problem, I can't. But I str has come to the rescue:
>
> R > str(rw)
> Time-Series [1:307] from 1690 to 1996: 0.986 1.347 1.502 1.594 1.475 ...
> R > str(pg)
> List of 264
> $ : num 0.227
> $ : num 0.189
> $ : num 0.237
> $ : num 0.235
>
> .
> .
> .
> .
> - attr(*, "dim")= int [1:2] 22 12
> - attr(*, "dimnames")=List of 2
>  ..$ : NULL
>  ..$ : chr [1:12] "Series 1" "Series 2" "Series 3" "Series 4" ...
> - attr(*, "tsp")= num [1:3] 1982 2003    1
> - attr(*, "class")= chr [1:2] "mts" "ts"
>
> Why is pg a list? pg was created by taking a row out of a much larger
> data.frame:
>
> R > pg <- ts(matrix(monthly.pg[1,-c(1:4)], ncol = 12, byrow = T), start =
> 1982)
> R > class(pg)
> [1] "mts" "ts"
> R > mode(pg)
> [1] "list"
>
> So, changing the mode to numeric, allowed me to intersect the ts:
>
> R > pg <- ts(matrix(as.numeric(monthly.pg[1,-c(1:4)]), ncol = 12, byrow =
> T), start = 1982)
> R > tsp(ts.intersect(rw, pg))
> [1] 1982 1996    1
>
> Weird. I suppose keeping on top of every object's mode is important.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list