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

Johann Petrak johann at ai.univie.ac.at
Tue May 15 15:10:00 CEST 2001


Thanks to all who helped on this!
Of course I messed up even my first help question on R and
asked the wrong question :)
>From list(c(1,2,3),c(4,5,6)) I wanted a data frame with
1 1 2 3
2 4 5 6

This is more interesting than what I actually asked, since
data frames are organized as lists of columns anyway,
so the efficient re-organization from a list of rows
is the point.
Naivly adapting Douglas' proposal seems to work:
data.frame(do.call("rbind",list(c(1,2,3),c(4,5,6))))
  X1 X2 X3
1  1  2  3
2  4  5  6
With lots of data, probably not very efficient?


So ... the reason why I want to do this in the first place 
is probably wrong R style:
I have a list of data frames (the result of a split operation).
For each member in the list, I want to calculate a couple of 
values using a single function that takes the member as an argument
and returns a list(vector) of values:
splitted <- (df, df[[1]])
myfun <- function (x) { calc all kinds of stuf from x, return c(...) }
res <- lapply(splitted,myfun)
  # this gives me a list of rows 

So is there a mapping operation that directly builds up a list
of columns? Or would the R programmer solve this completely 
differently?
(I cannot use different functions for each result column, since
they have to share code.)

Maybe doing an iterative append through vec<-c(vec,el)?
How efficient would this be? 
Is this different from vec<-append(vec,el) ?

Related to this:
How would I append single rows  to an existing dataframe in an efficient
and elegant manner? How all the rows from another dataframe?

Johann
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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