Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.GSO.4.44.0202260722330.17549-100000@auk.stats>
Date: 2002-02-26T07:26:33Z
From: Brian Ripley
Subject: Matrix of Elements of Different Types (was Interfacing    pre-existing C++ library from R)
In-Reply-To: <20020226014726.4F55B274E@sitemail.everyone.net>

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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._