[R] Correlation Matrix

Jeremy Miles jeremy.miles at gmail.com
Thu Apr 7 21:21:54 CEST 2011

On 7 April 2011 12:09, Dmitry Berman <ravenblur at gmail.com> wrote:
> Listers,
> I have a question regarding correlation matrices. It is fairly straight
> forward to build a correlation matrix of an entire data frame. I simply use
> the command cor(MyDataFrame). However, what I would like to do is construct
> a smaller correlation matrix using just three of the variable out of my data
> set.
> When I run this:
> cor(MyDataFrame$variable1, MyDataFrame$variable2,MyDataFrame$variable3) I
> get an error.
> Is there a way to do this through a built in function or is this something I
> have to construct manually?

You can use cbind().

cor(cbind(MyDataFrame$variable1, MyDataFrame$variable2,MyDataFrame$variable3) )


More information about the R-help mailing list