如何快速结合R中的60个矩阵 [英] how to combine 60 matrices in R quickly
本文介绍了如何快速结合R中的60个矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在R中有60个矩阵,分别命名为mat1,mat2 .... mat60,我想使用rbind将它们组合成一个大矩阵.我知道我可以写类似的东西
matList <- list(mat1, mat2, ... mat60)
rbind(matList)
但是这似乎是一个非常愚蠢的解决方案.知道如何简化流程吗?
我认为这个问题真的与OP必须手动键入矩阵名称有关.您可以使用mget
返回列表中的矩阵,然后使用@Michele构成的do.call
和rbind
这样(假设矩阵位于.GlobalEnv
中):matList <- mget(paste0("mat",1:60),env=globalenv())
bigm <- do.call("rbind" , matList)
I have 60 matrices in R named as mat1, mat2....mat60 and I would like to combine them into a big matrix using rbind. I know that I could write something like
matList <- list(mat1, mat2, ... mat60)
rbind(matList)
but it seems a very dumb solution. Any idea how I can simplify the process?
解决方案
I think this question really relates to the OP having to type out the names of the matrices manually. You can use mget
to return the matrices in a list and then use do.call
and rbind
as posed by @Michele like this (assuming the matrices are located in the .GlobalEnv
):
matList <- mget(paste0("mat",1:60),env=globalenv())
bigm <- do.call("rbind" , matList)
这篇关于如何快速结合R中的60个矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文