Correlation (Sparse and Dense Matrices)
cor.Rd
cor
computes the sample correlation between each column pair in sparse or
dense matrices.
Value
A p
xp
matrix where p
is the number of matrix columns, and the
(i
, j
) th element corresponds to the sample correlation between p_i
and p_j
.
Examples
x <- Matrix::rsparsematrix(10, 3, .5)
xdense <- as.matrix(x)
cor(x)
#> [,1] [,2] [,3]
#> [1,] 1.00000000 -0.03072093 0.4160101
#> [2,] -0.03072093 1.00000000 0.1651108
#> [3,] 0.41601009 0.16511083 1.0000000
cor(xdense)
#> [,1] [,2] [,3]
#> [1,] 1.00000000 -0.03072093 0.4160101
#> [2,] -0.03072093 1.00000000 0.1651108
#> [3,] 0.41601009 0.16511083 1.0000000