Dear R users, I'd like to compute "rho"(looks like a correlation matrix) with every two columns of "uu" matrix below.
Toy example, > uu <- matrix(1:15, nr=3, nc=5) > uu [,1] [,2] [,3] [,4] [,5] [1,] 1 4 7 10 13 [2,] 2 5 8 11 14 [3,] 3 6 9 12 15 rho <- function(x,y) { sum(x*y)/(sqrt(sum(x^2))*sqrt(sum(y^2))) } rho_12 <- rho(uu[,1],uu[,2]) rho_13 <- rho(uu[,1],uu[,3]) rho_14 <- rho(uu[,1],uu[,4]) rho_15 <- rho(uu[,1],uu[,5]) rho_23 <- rho(uu[,2],uu[,3]) rho_24 <- rho(uu[,2],uu[,4]) rho_24 <- rho(uu[,2],uu[,5]) rho_34 <- rho(uu[,3],uu[,4]) rho_35 <- rho(uu[,3],uu[,5]) rho_45 <- rho(uu[,4],uu[,5]) Actually, the matrix uu is huge, 20*1000. Would you plz tell me how to calculate "rho", more efficiently?? Any suggestion will be greatly appreciated. Best, Kathryn Lord [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.