Skip to content
Prev 387177 / 398502 Next

Dimensioning lists.

I have a setting in which it would be convenient to treat a list
as an array, i.e. to address its entries via a pair of indices.

A toy example:

xxx <- vector("list",9)
set.seed(42)
for(i in 1:9) xxx[[i]] <- list(a=sample(letters,1),b=sample(1:100,1))

I would like to be able to treat "xxx" as a 3 x 3 matrix.

I tried

   dim(xxx) <- c(3,3)

When I do, e.g.

    xxx[2,3]

I get:
That is I get a list of length 1, whose (sole) entry is the desired
object.  I would *like* to get just the desired object, *not* wrapped in
a list, i.e.:
(which is what I get by typing xxx[2,3][[1]]).

Is there any way to prevent the entries of xxx from being wrapped up in
lists of length 1?

Thanks for any enlightenment.

cheers,

Rolf Turner