x <- matrix(rnorm(400), nrow = 100)
# Call `cov(x)` to compare
fastcov2(x)
# Calculate covariance of subsets
fastcov2(x, col1 = 1, col2 = 1:2)
# Speed comparison
x <- matrix(rnorm(100000), nrow = 1000)
microbenchmark::microbenchmark(
fastcov2 = {
fastcov2(x, col1 = 1:50, col2 = 51:100)
},
cov = {
cov(x[,1:50], x[,51:100])
},
unit = 'ms', times = 10
)
Run the code above in your browser using DataLab