Skip to content
Prev 205363 / 398506 Next

vectors into a matrix

This is one of those times where do.call() comes in very handy: first
convert the vector names into a list using lapply and get() and then call
do.call with cbind on the list:

do.call(cbind,lapply(paste("VD",1:12,sep=""),get))

This also illustrates the virtue of putting such vectors in a list to begin
with, as then the lapply(paste...) operation can be dispensed with, making
things much more efficient.


Bert Gunter
Genentech Nonclinical Biostatistics
 
 
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Henrique Dallazuanna
Sent: Monday, January 04, 2010 11:00 AM
To: Victor Kyros
Cc: r-help at r-project.org
Subject: Re: [R] vectors into a matrix

Try this:

cbind(ID = as.numeric(gsub("VD", "", ls(patt = "VD\\d+"))) ,
t(sapply(ls(patt = "VD\\d+"), get)))
On Mon, Jan 4, 2010 at 3:32 PM, Victor Kyros <varenda44 at gmail.com> wrote:
http://www.R-project.org/posting-guide.html