根据向量名称识别并绑定多个向量 [英] Identify and cbind multiple vectors based on vector name
本文介绍了根据向量名称识别并绑定多个向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的工作区中有 100 个数字向量,名称为 sim1 到 sim100,长度都相同 (18).我试图找到一种方法来识别它们并绑定它们以创建一个 18 行 100 列的数据框.我可以轻松创建一个长度为 100 的字符向量,其中包含向量的名称:
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)]
..但我一直在思考如何创建对象本身的列表,我认为我可以将其与 do.call 一起使用.请问有什么建议吗?
..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?
推荐答案
你可以试试
do.call(cbind.data.frame, mget(paste0('sim', 1:100)))
或者如评论中提到的@Frank
Or as @Frank mentioned in the comments
data.frame(mget(paste0('sim', 1:100)))
这篇关于根据向量名称识别并绑定多个向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文