r - How to get a matrix of correlations with cor() function? -


i using base package of r in windows system.

i have 2 matrices have 1 column of numeric values. both matrices of same size.

i using following code

c<-cor(x,y) 

where x,y matrices size 10*1 c of size 1*1

the output single value. when use cor function should give output @ least equal size of matrix right?

if use summary(c) output should this:

    min. 1st qu.  median    mean 3rd qu.    max.   -0.2110 -0.0500  0.0946  0.1250  0.2680  0.7630 

but getting:

 min.   :0.06088    1st qu.:0.06088    median :0.06088    mean   :0.06088    3rd qu.:0.06088    max.   :0.06088  

you need put x , y in data.frame or matrix work. here quick example

set.seed(4)  #so have same random numbers x<-rnorm(100) y<-rnorm(100) w<-cor(data.frame(x,y)) w             x          y x  1.0000000 -0.1338078 y -0.1338078  1.0000000  as.vector(w) [1]  1.0000000 -0.1338078 -0.1338078  1.0000000 

you can wrap cor in as.vector store vector if like.


Comments