Define and cbind multiple vectors based on the vector name

I have 100 numeric vectors named sim1 to sim100 in my artboard, with the same length (18). I am trying to find a way to identify them and bind them to create a data frame of 18 rows and 100 columns. I can easily create a 100 character vector that contains the vector names:

myvector<-ls()
myvector<-[grep("sim",myvector)]

      

.. but I got stuck on how to create a list of the objects themselves, which I believe I could use with do.call. Any suggestions please?

+3


source to share


1 answer


You may try

 do.call(cbind.data.frame, mget(paste0('sim', 1:100)))

      



Or like @Frank mentioned in the comments

 data.frame(mget(paste0('sim', 1:100)))

      

+2


source







All Articles