从给定的 LT 索引创建稀疏矩阵,但填充其他列表中的值
Create sparse matrices from given LT indices but fill with values in other list
我有三个列表:
"corMat" "corMatPVAL" "index"
> head(corMat)
[,1]
[1,] 0.7786662
[2,] 0.7536617
[3,] 0.7950954
[4,] 0.7950954
[5,] 0.7950954
[6,] 0.7388970
> head(corMatPVAL)
[,1]
[1,] 6.166382e-155
[2,] 1.304651e-139
[3,] 3.756711e-166
[4,] 3.756711e-166
[5,] 3.756711e-166
[6,] 2.097761e-131
> head(index)
[,1]
[1,] 82
[2,] 271
[3,] 441
[4,] 442
[5,] 443
[6,] 501
我必须制作两个大小为 48389 行和 48389 列的矩阵,即一个用于填充第三个列表(索引)中提供的索引的 corMat 值(第一个列表)和一个 corMatPVAL(第二个列表)矩阵填充与第三个列表(索引)中提到的相同索引。
注意:索引只是矩阵的下三角。请告诉我如何制作矩阵,然后将这些列表值映射为矩阵形式。
第三个列表中提到的索引。矩阵的对角线和 [=17=] 部分可以是 NA
library(Matrix)
sparseMatrix(index, seq_along(index), , corMat, c(48389, 48389))
sparseMatrix(index, seq_along(index), , corMatPVAL, c(48389, 48389))
可能很难将输出可视化,所以举个小例子:
sparseMatrix(10:6, 1:5, , 1:5/10, c(10, 10))
#10 x 10 sparse Matrix of class "dgCMatrix"
#
# [1,] . . . . . . . . . .
# [2,] . . . . . . . . . .
# [3,] . . . . . . . . . .
# [4,] . . . . . . . . . .
# [5,] . . . . . . . . . .
# [6,] . . . . 0.5 . . . . .
# [7,] . . . 0.4 . . . . . .
# [8,] . . 0.3 . . . . . . .
# [9,] . 0.2 . . . . . . . .
#[10,] 0.1 . . . . . . . . .
我有三个列表:
"corMat" "corMatPVAL" "index"
> head(corMat)
[,1]
[1,] 0.7786662
[2,] 0.7536617
[3,] 0.7950954
[4,] 0.7950954
[5,] 0.7950954
[6,] 0.7388970
> head(corMatPVAL)
[,1]
[1,] 6.166382e-155
[2,] 1.304651e-139
[3,] 3.756711e-166
[4,] 3.756711e-166
[5,] 3.756711e-166
[6,] 2.097761e-131
> head(index)
[,1]
[1,] 82
[2,] 271
[3,] 441
[4,] 442
[5,] 443
[6,] 501
我必须制作两个大小为 48389 行和 48389 列的矩阵,即一个用于填充第三个列表(索引)中提供的索引的 corMat 值(第一个列表)和一个 corMatPVAL(第二个列表)矩阵填充与第三个列表(索引)中提到的相同索引。
注意:索引只是矩阵的下三角。请告诉我如何制作矩阵,然后将这些列表值映射为矩阵形式。 第三个列表中提到的索引。矩阵的对角线和 [=17=] 部分可以是 NA
library(Matrix)
sparseMatrix(index, seq_along(index), , corMat, c(48389, 48389))
sparseMatrix(index, seq_along(index), , corMatPVAL, c(48389, 48389))
可能很难将输出可视化,所以举个小例子:
sparseMatrix(10:6, 1:5, , 1:5/10, c(10, 10))
#10 x 10 sparse Matrix of class "dgCMatrix"
#
# [1,] . . . . . . . . . .
# [2,] . . . . . . . . . .
# [3,] . . . . . . . . . .
# [4,] . . . . . . . . . .
# [5,] . . . . . . . . . .
# [6,] . . . . 0.5 . . . . .
# [7,] . . . 0.4 . . . . . .
# [8,] . . 0.3 . . . . . . .
# [9,] . 0.2 . . . . . . . .
#[10,] 0.1 . . . . . . . . .