[R] ts.intersect a multivariate and univariate ts

Andy Bunn abunn at whrc.org
Sun Jun 5 19:16:14 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.

I see, I was confusing class and mode. However, since a list can be a ts
object as in this example:

R > w <- list(rnorm(10), rnorm(10))
R > x <- ts(w, start = 1980)
R > y <- ts(rnorm(10), start = 1981)
R > tsp(x); tsp(y)
[1] 1980 1981    1
[1] 1981 1990    1
R > class(x); class(y)
[1] "ts"
[1] "ts"
R > mode(x); mode(y)
[1] "list"
[1] "numeric"
R > z <- ts.intersect(x,y)
Error: incorrect number of subscripts on matrix
R >

What would be the easiest way to make x a mts that could be used with plot
or ts.intersect?

R > z <- ts.intersect(x[[1]], x[[2]],y)
R > z
Time Series:
Start = 1981
End = 1990
Frequency = 1
          x[[1]]     x[[2]]           y
1981 -0.01809700  1.0725645 -2.05558318
1982  3.68646780 -1.7109873  0.99807704
1983 -2.24591782  1.0401845  0.66387636
1984 -1.09823787 -0.5579356  0.09377471
1985  0.25234527  2.9093321 -2.29570622
1986 -0.02486054  0.2631546 -1.16989266
1987 -0.11290772  0.6176711  1.10653249
1988 -1.23308983  0.1578497  0.65200013
1989  0.33531558 -0.8943133  0.84397066
1990  0.35412243 -1.0974815  0.41322884
R >

-Andy




More information about the R-help mailing list