[R] Very slow: using double apply and cor.test to compute correlation p.values for 2 matrices

Daren Tan daren76 at hotmail.com
Wed Nov 26 05:55:00 CET 2008


My two matrices are roughly the sizes of m1 and m2. I tried using two apply and cor.test to compute the correlation p.values. More than an hour, and the codes are still running. Please help to make it more efficient. 
 
m1 <- matrix(rnorm(100000), ncol=100)
m2 <- matrix(rnorm(10000000), ncol=100)

cor.pvalues <- apply(m1, 1, function(x) { apply(m2, 1, function(y) { cor.test(x,y)$p.value }) })



More information about the R-help mailing list