Identify and cbind multiple vectors based on vector name

白昼怎懂夜的黑 提交于 2021-01-27 14:30:54

问题


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

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

..but I'm stuck on how to create a list of the objects themselves that I assume I could then use with do.call. Any suggestions please?


回答1:


You can try

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

Or as @Frank mentioned in the comments

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


来源:https://stackoverflow.com/questions/30462753/identify-and-cbind-multiple-vectors-based-on-vector-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!