[R] an efficient way to calculate correlation matrix

2011-06-02 Thread Bill Hyman
Dear all, I have a problem. I have m variables each of which has n observations. I want to calculate pairwise correlation among the m variables and store the values in a m x m matrix. It is extremely slow to use nested 'for' loops if m and n are large. Is there any efficient alternative to

Re: [R] an efficient way to calculate correlation matrix

2011-06-02 Thread Dennis Murphy
?cor Example: dd - data.frame(x1 = rnorm(40), x2 = rnorm(40), x3 = runif(40, 0, 10)) 'data.frame': 40 obs. of 3 variables: $ x1: num -0.5585 1.3831 -1.7862 0.0572 0.2825 ... $ x2: num -0.5247 -0.8636 -0.0749 0.2399 -0.1592 ... $ x3: num 7.698 5.259 0.918 3.251 5.169 ... cor(dd)