[R] Is there any Command showing correlation of all variables in a dataset?

Mike Marchywka marchywka at hotmail.com
Tue Mar 1 12:47:13 CET 2011












----------------------------------------
> Date: Tue, 1 Mar 2011 02:41:00 -0800
> From: joongi at hanmail.net
> To: r-help at r-project.org
> Subject: [R] Is there any Command showing correlation of all variables in a dataset?
>
>
> Thanks in advance.
>
> I want to derive correlations of variables in a dataset
>
> Specifically
>
> library(Ecdat)
> data(Housing)
> attach(Housing)
> cor(lotsize, bathrooms)
>
> this code results only the correlationship between two variables.
> But I want to examine all the combinations of variables in this dataset.
> And I will finally make a table in Latex.
>
> How can I test correlations for all combinations of variables?
> with one simple command?
>

This appears to work as expected although I don't have enough
intuition to know if these numbers are plausible beyond rough
guess( diag of course is one LOL), 

> df<-data.frame(a=rnorm(100), b=runif(100),c=runif(100)+rnorm(100))
> str(df)
'data.frame':   100 obs. of  3 variables:
 $ a: num  0.1841 0.2296 -1.2251 0.0898 -0.961 ...
 $ b: num  0.586 0.343 0.821 0.41 0.352 ...
 $ c: num  -0.373 2.225 0.102 1.186 -0.737 ...
> cor(df)
           a           b           c
a 1.00000000  0.07710107  0.11088579
b 0.07710107  1.00000000 -0.02424471
c 0.11088579 -0.02424471  1.00000000
> ?cor


> df<-data.frame(a=.1*rnorm(100), b=(1:100)/100,c=(1:100)/100+.1*rnorm(100))
> cor(df)
             a           b            c
a  1.000000000 -0.01970874 -0.003665239
b -0.019708737  1.00000000  0.950375445
c -0.003665239  0.95037544  1.000000000
>



 		 	   		  


More information about the R-help mailing list