[R] joining matrices, vectors, scalars in one object

From: Gonšalo Ferraz <gferraz29_at_gmail.com>
Date: Thu, 13 Mar 2008 09:04:11 -0400


Hi,

I have:

a <- matrix(c(0,1,0,1),nrow=2)
b <- matrix(c(1,1,1,0,0,0),nrow=3)
c <- 1
d <- c(1,0,1)

And I would like to join them in an object 'thing' so that I can access a, b, c, or d through an index in a for loop.

For example:
thing[4]
would return
[1] 1 0 1

Note however, that I have many of these 'thing' components. So many that a command like

thing <- list(a = matrix(c(0,1,0,1),nrow=2), b = matrix(c (1,1,1,0,0,0),nrow=3), c = 1, d = c(1,0,1))

would become long and awkward.

Is there a way of declaring an empty 'thing' of a given length and then assigning its elements from a for loop? I need to allow elements a, b, c... that can be scalars, vectors or matrices with varying dimensions.

Thanks!

Gonšalo

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 13 Mar 2008 - 13:23:01 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 13 Mar 2008 - 14:00:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive