[R] Re: Matrix of Elements of Different Types (was Interfacing pre-existing C++ library from R)

Prof Brian D Ripley ripley at stats.ox.ac.uk
Tue Feb 26 08:26:33 CET 2002


On Mon, 25 Feb 2002, Gabor Grothendieck wrote:

>
>
> --- Prof Brian D Ripley <ripley at stats.ox.ac.uk> wrote:
> >A matrix list?  R lists are just vectors with elements of different types,
> >and R matrices are just vectors with a dimension attribute.
>
> When I saw the above I tried to create a matrix from a list but
> could not get it to work:
>
>  my.lm <- lm( rnorm(10) ~ I(1:10) )
>  my.list <- list(1, 2, 3, 4, 5, 6, my.lm, my.lm, my.lm)
>  my.mat <- matrix( my.list, nrow=3 )
>
> gives the following error in R 1.4.0 on Windows 2000:
>
>  Error in matrix(my.list, nrow = 3) : Unimplemented feature in
>   copyVector
>
> Is there a way to create a matrix out of elements of different types?

> dim(my.list) <- c(3,3)
> my.list
     [,1]        [,2]        [,3]
[1,] "Numeric,1" "Numeric,1" "List,12"
[2,] "Numeric,1" "Numeric,1" "List,12"
[3,] "Numeric,1" "Numeric,1" "List,12"

`R matrices are just vectors with a dimension attribute' should have given
you a clue!

The matrix() route does work in S.

-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list