[R] Qs on "vector of lists", etc.

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Jun 1 21:10:21 CEST 2011



On 01.06.2011 18:59, Roy Shimizu wrote:
> I'm pretty new to R, so please forgive the cluelessness of these questions.
>
> Is it true that it is not possible to have a "vector or lists" in R?
>
> Is a "list of lists" the closest one can get to a "vector of lists"?

Actually a list is a vector of mode "list".

Hence if you have a list of lists, it *is* a vector of lists and behaves 
consistantly (e.g. when subsetiing with [] rather than [[]]).

L <- list(list(a=1, b=2), list(c=3, d=4))

L[1] # L can be considered a vector of mode list.



> Is it possible to have a "matrix of lists" in R?  Or an "array of lists"?

Yes:

  X <- matrix(L, nrow=2)
  X[1,1]
  X[2,1]

or even:

  dim(X) <- c(1,2,1)
  mode(X)  # "list"
  class(X) # "array"

Uwe Ligges




> Thanks!
>
> Roy
>
> 	[[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