[R] ts.intersect a multivariate and univariate ts

Gabor Grothendieck ggrothendieck at myway.com
Sat Jun 4 21:27:58 CEST 2005


Andy Bunn <abunn <at> whrc.org> writes:

: 
: 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:

We can provide it in a reproducible way like this:

dput(rw)
dput(pg)

That will output both in a format that anyone else can paste
back into R from your email.

: 
: 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:

A data frame is a list with one component per column so taking
a matrix of a data frame gives something like this:

R> matrix(iris)
     [,1]       
[1,] Numeric,150
[2,] Numeric,150
[3,] Numeric,150
[4,] Numeric,150
[5,] factor,150 

which is a matrix each of whose elements is a column of the original
data frame.  What you really want here is 'as.matrix' or 'data.matrix', 
not 'matrix'.




More information about the R-help mailing list