[R] list to data frame by rows ...

Johann Petrak johann at ai.univie.ac.at
Fri May 18 18:40:47 CEST 2001

Peter Dalgaard BSA wrote:
> > > [...]
> > > > cl <- 1:2
> > > > names(cl) <- c("a","b")
> > > > as.data.frame(lapply(cl,function(i)sapply(result,"[[",i)))
> > >   a b
> > > x x 2
> > > y y 4
> > >
> [...]
> Umm, did I come across as intended there? I'm not "pulling anything
> out" of do4split with that code, I'm working on the result of it
> (after result <- lapply(splitted, do4split) ). If you have code that
> generates a list of lists which all have similar structure (i.e. they
> can have mixed type but it must be the same mix for all) then that
> kind of code should be able to do the conversion to a data frame. It's
> a bit wasteful of storage though, since list storage has a rather
> large overhead.

Ummm you didnt because I misunderstood it :/
 - but now I understand what is going on here, its exactly 
what I wanted!

(BTW its quite faster than doing it with the for loop, even if
I preallocate ltmp and just reassign the elements.)
> > I would be curious how efficient this is and what actually happens.
> > Will ltmp[[i]]<-c(ltmp[[i]],tmp[[i]]) just extend the column or
> > will the whole content be copied every time?
> It will be copied, so you do not want to do that...!

What is the best way to learn about how things are done internally in R?
I didnt come across this anywhere in the documentation, but
maybe I overlooked it.

It would be nice to have something like "R for programmers"
that elaborates a bit on the internal data structures, 
and the kind and efficiency of (basic) operations  on them.
Like, every LISP programmer knows which operations on lists
will be fast and which slow, and how e.g. make appending
to the end of a list fast, when do shallow or deep copies
occur, what will cause GC and what avoids it.

So just as a basic question here: will all assignments of big
datastructures always do a deep copy?
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list