-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 
--
--
--
--
2
  • 1) Did you mean 700 Rows and 25 Columns? 2) If you are doing this in Excel, did you check out the =CORREL()? Commented Jun 23, 2012 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. Commented Jun 24, 2012 at 6:38

2 Answers 2

2

This might do the trick:

table <- read.xls(file)
x <- table[1:699]
y <- table[700]
cor(x, y)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for your perfect answer. I think, you only understood my question clearly.
to be honest, it was a Google search away
2

Have a look at ?cor.

For example:

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

Gives you all the correlations.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.