-3

Possible Duplicate:
correlation matrix in r

I have an excel sheet which has 700 columns and 25 rows. The sample of my file is shown below. I would like to calculate the correlation coefficient between A1 and A700, A2 and A700, A3 and A700 ,A4 and A700 and so on. What is the easiest way to do this with R?

       A1     A2     A3     A4   ---- --- A700

 A    2.7     5       4     34             34
 B    5.67   7.8      6     45            25.6
 C    2.3    -9      12.5   13            2.8
 D    5.6    6       -56    2.5          -66.7
 E    7.8    5       20     6.7          -56.8 
--
--
--
--
Community
  • 1
  • 1
sagar
  • 129
  • 2
  • 5
  • 1) Did you mean 700 Rows and 25 Columns? 2) If you are doing this in Excel, did you check out the `=CORREL()`? – Siddharth Rout Jun 23 '12 at 15:25
  • @JoshuaUlrich Did you understand my question? I don't want to create a matrix. I need to print the correlation coefficients only. Dear friend, please check my accepted answer. I think, this is not a duplicate question. In my case, the number of rows and columns are not equal. – sagar Jun 24 '12 at 06:38

2 Answers2

2

Have a look at ?cor.

For example:

m <- matrix(rnorm(100), nrow=10)
cor(m)

Gives you all the correlations.

johannes
  • 14,043
  • 5
  • 40
  • 51
2

This might do the trick:

table <- read.xls(file)
x <- table[1:699]
y <- table[700]
cor(x, y)
danuker
  • 861
  • 10
  • 26