I have 2 large matrices (typically of dimensions 5000*40 and 20000*40). I am trying to create a correlation matrix, where i would like to calculate the correlation of each row from the first matrix to every other row in the second matrix. I have following minimal code, by it takes extremely long time. Any recommendations to speed it up or parallize. Thanks
-Jaison
nprots <- 50 #usually ca. 5000
ngenes <- 1000 #usually ca. 20000
a_mat <- matrix( runif(40*nprots, 120, 116000), ncol=40)
b_mat <- matrix( runif(40*ngenes, 0.1, 1000), ncol=40)
system.time(apply( a_mat, 1, function(xx)
apply(b_mat, 1, cor, y = xx, use = "pairwise.complete.obs")) -> cor_mat)