On 06.04.2010 23:28, David.Epstein wrote:

How do I append an R-object to a list?
I want to start with an empty list, and append R-objects one by one.
Does this start with a command like
mylist<- NULL
??

I have read a few answers on R-help to questions like this, but they all
seem to be well off the point. Sometimes it's assumed that the list is a
vector---not my case.
One answer I read said that the object appended must be a list. This doesn't
make sense to me. I don't want a list of lists. I want a list of R-objects.

I tried using c(with.stuff.inside.the.brackets). This seemed to unwrap my
structures, storing the individual components rather than the R-objects
themselves.

I tried looking in "Intro to R" but could find nothing relevant.

Thanks for any help.
David




Well lists are vectors of mode list.

If you have a list L and want to append an element l, you can simply add it by:

c(L, list(l))

One element of a List L extracted by vector indexing (single brackets):
L[1]
will show you got a list of length one back (since L is a vector of mode list).

You may want to play around and find that things are even simpler than you thought they are.


Uwe Ligges

______________________________________________
R-help@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.

Reply via email to