[R] list to data frame by rows ...
Douglas Bates
bates at stat.wisc.edu
Wed May 9 17:09:16 CEST 2001
Johann Petrak <johann at ai.univie.ac.at> writes:
> Ugh, newbie question ... :
>
> I have a list of vectors of equal size, like
> list(c(1,2,3),c(4,5,6))
> and want to convert this into a data frame row-wise:
>
> 1 1 4
> 2 2 5
> 3 3 6
>
> Whats the elegant/R-way to do this?
In general the cbind function is used to bind columns into an array.
If you want to invoke it on a list of arguments you can use do.call to
create the function call. Combining these gives
> mylist <- list(c(1,2,3),c(4,5,6))
> do.call("cbind", mylist)
[,1] [,2]
[1,] 1 4
[2,] 2 5
[3,] 3 6
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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