Skip to content
Back to formatted view

Raw Message

Message-ID: <442FA175-A8C3-4695-A5F1-B8748A484E18@comcast.net>
Date: 2011-10-11T08:31:28Z
From: David Winsemius
Subject: binding all elements of list (character vectors) to a matrix as rows
In-Reply-To: <CA+=LhL2SBACMb7rzO7T86awMcnPtd2bUTL07aTKvwuywc-GWug@mail.gmail.com>

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