[R] Generalized 2D list/array/whatever?

Gabor Grothendieck ggrothendieck at gmail.com
Fri Apr 24 04:20:07 CEST 2009


Matrix made from a list:

m <- list(sin, 1:3, letters[1:3], expression(a+b))
dim(m) <- c(2, 2)
dimnames(m) <- list(letters[1:2], LETTERS[1:2])
class(m) # matrix

or

M <- structure(list(sin, 1:3, letters[1:3], expression(a+b)), .Dim = c(2, 2),
  .Dimnames = list(c("a", "b"), c("A", "B")))
class(M) # matrix

On Thu, Apr 23, 2009 at 10:03 PM, Toby <tobias.weingartner at gmail.com> wrote:
> I'm trying to figure out how I can get a generalized 2D
> list/array/matrix/whatever
> working.  Seems I can't figure out how to make the variables the right
> type.  I
> always seem to get some sort of error... out of bounds, wrong type, wrong
> dim, etc.
> Very confused... :)
>
> x[["some label", "some other index"]] <- 3
> x[["some other label", "something else"]] <- 4
>
> I don't know the indexes/label ahead of time... they get generated...  Any
> thoughts?
>
> -Toby.
>
>        [[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.
>




More information about the R-help mailing list