I have two matrices of the same size. I would like to calculate the correlation coefficient between each pair of rows in these matrices; row 1 from A with row 1 B, row 2 from A
This should be fast:
cA <- A - rowMeans(A) cB <- B - rowMeans(B) sA <- sqrt(rowMeans(cA^2)) sB <- sqrt(rowMeans(cB^2)) rowMeans(cA * cB) / (sA * sB)