简体   繁体   English

根据向量名称识别并绑定多个向量

[英]Identify and cbind multiple vectors based on vector name

I have 100 numeric vectors named sim1 to sim100 in my workspace, all of the same length (18).我的工作区中有 100 个名为 sim1 到 sim100 的数字向量,它们的长度都相同(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.我试图找到一种方法来识别它们并绑定它们以创建一个 18 行 100 列的数据框。 I can easily create a character vector of length 100 that contains the names of the vectors:我可以轻松创建一个长度为 100 的字符向量,其中包含向量的名称:

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. ..但我坚持如何创建对象本身的列表,我认为我可以将其与 do.call 一起使用。 Any suggestions please?请问有什么建议吗?

You can try你可以试试

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

Or as @Frank mentioned in the comments或者正如评论中提到的@Frank

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM