[R] ts.intersect a multivariate and univariate ts

Andy Bunn abunn at whrc.org
Sat Jun 4 20:07:36 CEST 2005


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.

Thanks for the push forward.

-Andy




More information about the R-help mailing list