Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/75.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 cbind保留唯一列的列表矩阵_R_List_Matrix_Reduce - Fatal编程技术网

R cbind保留唯一列的列表矩阵

R cbind保留唯一列的列表矩阵,r,list,matrix,reduce,R,List,Matrix,Reduce,我有一个矩阵列表,在列表元素中,一些列是多余的,我想将该列表简化为一个矩阵,只保留唯一的列 以下是一个示例数据: set.seed(1) #starting matrix mat <- matrix(rnorm(10*6),nrow=10,dimnames=list(NULL,c("a_1","a_2","b_1","b_2","c_1","c_2"))) mat.list <- list(mat[,c(1,2,3,4)],mat[,c(1,2,5,6)],mat[,c(3,4,5,

我有一个矩阵列表,在列表元素中,一些列是多余的,我想将该列表简化为一个矩阵,只保留唯一的列

以下是一个示例数据:

set.seed(1)
#starting matrix
mat <- matrix(rnorm(10*6),nrow=10,dimnames=list(NULL,c("a_1","a_2","b_1","b_2","c_1","c_2")))
mat.list <- list(mat[,c(1,2,3,4)],mat[,c(1,2,5,6)],mat[,c(3,4,5,6)])
set.seed(1)
#起始矩阵
材料试验
m1
res.mat <- Reduce(cbind,mat.list)
Reduce(function(x,y)cbind(x,y[,!colnames(y)%in%colnames(x)]),mat.list)
             a_1         a_2         b_1         b_2        c_1        c_2
 [1,] -0.6264538  1.51178117  0.91897737  1.35867955 -0.1645236  0.3981059
 [2,]  0.1836433  0.38984324  0.78213630 -0.10278773 -0.2533617 -0.6120264
 [3,] -0.8356286 -0.62124058  0.07456498  0.38767161  0.6969634  0.3411197
 [4,]  1.5952808 -2.21469989 -1.98935170 -0.05380504  0.5566632 -1.1293631
 [5,]  0.3295078  1.12493092  0.61982575 -1.37705956 -0.6887557  1.4330237
 [6,] -0.8204684 -0.04493361 -0.05612874 -0.41499456 -0.7074952  1.9803999
 [7,]  0.4874291 -0.01619026 -0.15579551 -0.39428995  0.3645820 -0.3672215
 [8,]  0.7383247  0.94383621 -1.47075238 -0.05931340  0.7685329 -1.0441346
 [9,]  0.5757814  0.82122120 -0.47815006  1.10002537 -0.1123462  0.5697196
[10,] -0.3053884  0.59390132  0.41794156  0.76317575  0.8811077 -0.1350546