Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.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 使用apply将两个矩阵转换为一个列表_R_Apply - Fatal编程技术网

R 使用apply将两个矩阵转换为一个列表

R 使用apply将两个矩阵转换为一个列表,r,apply,R,Apply,我有两个矩阵,列数相同,但行数不同: a <- cbind(runif(5), runif(5)) b <- cbind(runif(8), runif(8)) 因此,结果如下所示: > print(my_result) [[1]] [[1]][[1]] [1] 0.9440956 0.7259602 0.7804068 0.7115368 0.2771190 [[1]][[2]] [1] 0.4155642 0.1535414 0.6983123 0.7578231 0.

我有两个矩阵,列数相同,但行数不同:

a <- cbind(runif(5), runif(5))
b <- cbind(runif(8), runif(8))
因此,结果如下所示:

> print(my_result)
[[1]]
[[1]][[1]]
[1] 0.9440956 0.7259602 0.7804068 0.7115368 0.2771190

[[1]][[2]]
[1] 0.4155642 0.1535414 0.6983123 0.7578231 0.2126765 0.6753884 0.8160817
[8] 0.6548915

[[2]]
[[2]][[1]]
[1] 0.7343330 0.7751599 0.4463870 0.6926663 0.9692621

[[2]][[2]]
[1] 0.5708726 0.1234482 0.2875474 0.4760349 0.2027653 0.5142006 0.4788264
[8] 0.7935544
如果没有
for
循环,我想不出该怎么做,但我很确定这里可以使用一些
*pply
魔术


任何指导都将不胜感激。

我不确定您要寻找的解决方案有多普遍(任意数量的矩阵、传递矩阵列表的能力等),但这适用于您的具体示例:

lapply(1:2,function(i){list(a[,i],b[,i])})
lapply(1:2,function(i){list(a[,i],b[,i])})