Correlation Matrix in R CRAN

Here it should be assumed that you have the values as columns on a spreadsheet and everywhere you don’t have a value you have replaced the gap with the letters NA.

Month A B C D E
Apr 63.91419 21.13823 75.13719 80.97858 11.86916
May 92.51104 126.4206 129.9751 56.79248 36.77565
Jun 65.44783 39.14822 6.558068 19.42456 21.63901
Jul 131.4266 70.55551 63.00389 102.5545 116
Aug 129.3926 31.60157 2.435477 NA 73.03078
Sep 35.71819 6.667624 89.68176 98.86681 26.59825
Oct 53.36333 97.32301 63.80283 2.39816 41.05988
Nov 38.88958 88.80514 118.4024 3.027732 64.32666
Dec NA 123.3156 123.5542 79.57653 62.26653
Jan 6.570292 11.66491 72.28813 31.43667 39.0891
Feb 15.1047 9.964003 144.4861 48.67408 146.2865
Mar 78.85201 10.53091 147.5341 67.90013 40.08176

Copy The Data into the clipboard:

cr<-read.table("clipboard",header=TRUE, na.strings="NA" )
x <-cr[2:5]
 cm<-cor(x,x,use = "pairwise.complete.obs")

Now output the Matrix back to the clipboard

write.table(cm,"clipboard",sep="\t")

and paste it back into Excel &c.

If you get a buffer full error then use :

write.table(cm,"clipboard-2048",sep="\t")

instead

A B C D
A 1 0.3 -0 0.4
B 0.3 1 0.2 -0
C -0 0.2 1 0.2
D 0.4 -0 0.2 1

Leave a Reply