[R] binding all elements of list (character vectors) to a matrix as rows

David Winsemius dwinsemius at comcast.net
Tue Oct 11 10:31:28 CEST 2011


On Oct 11, 2011, at 2:47 AM, Marion Wenty wrote:

> dear r-users,
>
> i have got a problem which i am trying to solve:
>
> i have got the following commands:
>
> Mymatrix <- matrix(1:9,ncol=3)
> Z <-
> list
> ("V1
> "=c("a","",""),"V2"=c("b","",""),"V3"=c("c","",""),"V4"=c("d","",""))

rbind(Mymatrix, t(as.data.frame(Z)))

The next method could be used if you had more lists:

do.call(rbind, list(Mymatrix, t(as.data.frame(Z))))


> Mymatrix <- rbind(Mymatrix,Z[[1]],Z[[2]],Z[[3]],Z[[4]])
>
> now this is working, but i would like to substitute
>
> Z[[1]],Z[[2]],Z[[3]],Z[[4]]
>
> for a command with which i could also use another list with a  
> different
> number of elements, e.g. 5 or 6 elements.
-- 

David Winsemius



More information about the R-help mailing list