Re: [R] list()

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Wed, 19 Mar 2008 09:14:16 -0400 (EDT)


I cannot remember seeing any specific tutorial on the use of list(). There are bits and pieces here and there but outside of the little bit in the Intro to R I cannot think of any.

For your specific question about names you can always assign (new) names to a list

 # Examples
# No name
aa <- list(rnorm(10,5,2), LETTERS[1:5])
aa
# Names
names(aa) <- c("numbers", "letters")
aa
# Change name of first element of list
names(aa)[1] <- "randoms"
aa

> Is anyone familiar with a good tutorial (in print or
> online) on the
> use of list()? I found Matlab structures to be a
> great way to pass
> complex variables (such as a model consisting of
> differently-
> dimensioned variables) back and forth between
> functions. It seems
> list() requires that you define the components
> within the command
> (model <- list( var1 =" ", var2 = " ", etc) and that
> if you don't
> fully define and name the component variables WITHIN
> the list command,
> you won't be able to refer to them by name
> elsewhere. Instead, you
> will have to remember the order and call the
> component variables as
> model[[1]] etc. instead of model$var1. Is this a
> correct
> understanding? Are there any good, comprehensive
> explanations on
> list() with examples?
>
> Thanks!
>
> ______________________________________________
> 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.
>



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 Wed 19 Mar 2008 - 13:17:35 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 Wed 19 Mar 2008 - 14:30:23 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