Skip to contents

cor computes the sample correlation between each column pair in sparse or dense matrices.

Usage

cor(x, ...)

# S3 method for default
cor(x, ...)

# S3 method for CsparseMatrix
cor(x, ...)

Arguments

x

A matrix or CsparseMatrix.

...

Additional arguments to pass to methods.

Value

A pxp matrix where p is the number of matrix columns, and the (i, j) th element corresponds to the sample correlation between p_iand p_j.

Details

cor() is an S3 generic with methods for:

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