Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R将索引变量组合成一个向量_R_Vector - Fatal编程技术网

R将索引变量组合成一个向量

R将索引变量组合成一个向量,r,vector,R,Vector,我有以下变量x11 x12 x13 x21 x22 x23…x51、x52、x53 我想要一个包含所有上述值的向量 我不建议任何人这样做,但你可以 arr <- c() for (i in c(11:53)) { arr <- c(arr, get(sprintf("x%d", i))) } arr#获取全局环境中名称与模式匹配的所有变量名 答案可能取决于细节。您应该尝试制作一个可复制的示例(例如,仅使用x11-x13缩小)。我猜:unlist(mget(paste0('x',

我有以下变量x11 x12 x13 x21 x22 x23…x51、x52、x53

我想要一个包含所有上述值的向量


我不建议任何人这样做,但你可以

arr <- c()
for (i in c(11:53)) {
  arr <- c(arr, get(sprintf("x%d", i)))
}
arr
#获取全局环境中名称与模式匹配的所有变量名

答案可能取决于细节。您应该尝试制作一个可复制的示例(例如,仅使用x11-x13缩小)。我猜:
unlist(mget(paste0('x',11:53))
unlist(mget(ls(pattern=“^x\d{2}$”)))
t(sapply(paste0('x',1:5),paste0,1:3))
???这些是变量吗?然后做
mget(t(sapply(paste0(“x”,1:5),paste0,1:3))
不熟悉这种方法,将尝试一下!
arr <- c()
for (i in c(11:53)) {
  arr <- c(arr, get(sprintf("x%d", i)))
}
# get all varnames in global environment with name that matches pattern
vars <- ls()[grepl("x", ls())] 

# combine those objects
unlist(lapply(vars, get))