sparse_cor | R Documentation |
Safe correlation function which returns a sparse matrix without missing values
sparse_cor(
x,
y = NULL,
method = "pearson",
allow_neg = TRUE,
remove_na = TRUE,
remove_inf = TRUE,
...
)
x |
Sparse matrix or character vector. |
y |
Sparse matrix or character vector. |
method |
Method to use for calculating the correlation coefficient. |
allow_neg |
Logical. Whether to allow negative values or set them to 0. |
remove_na |
Logical. Whether to replace NA values with 0. |
remove_inf |
Logical. Whether to replace infinite values with 1. |
... |
Other arguments passed to |
A correlation matrix.
## Not run:
m1 <- simulate_sparse_matrix(
2000, 2000,
density = 0.01
)
m2 <- simulate_sparse_matrix(
2000, 1000,
density = 0.05
)
all.equal(
as_matrix(sparse_cor(m1)),
as_matrix(cor(as_matrix(m1)))
)
all.equal(
as_matrix(sparse_cor(m1, m2)),
as_matrix(cor(as_matrix(m1), as_matrix(m2)))
)
system.time(
sparse_cor(m1)
)
system.time(
cor(as_matrix(m1))
)
system.time(
sparse_cor(m1, m2)
)
system.time(
cor(as_matrix(m1), as_matrix(m2))
)
m1[sample(1:500, 10)] <- NA
m2[sample(1:500, 10)] <- NA
sparse_cor(m1, m2)[1:5, 1:5]
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.