2

I want to create a correlation matrix given the "data1.new"-dataset. I know that ´NA´ values are represented by question marks. I have removed the NA values by using the "complete.obs".

data1.new<-data1[4:11]
summary(data1.new)
cor(data1.new, use = "complete.obs")
library(corrplot)
forcorrplot <- cor(data1.new)
corrplot(forcorrplot, method="number",shade.col=NA, tl.col="black", tl.srt=45)

My results are as follows:

Results

Phil
  • 7,287
  • 3
  • 36
  • 66
Seline
  • 35
  • 1
  • 5
  • 1
    Hi S.S, welcome to Stack Overflow. Please provide us with at least a sample of `data` with `dput(data)` or `dput(data[1:10,])` by editing your post with the output. See [How to make a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for more info. – Ian Campbell Apr 10 '20 at 18:16

1 Answers1

1

The issue is that cor with complete.obs is not assigned to the object forcorrplot

library(corrplot)
data(mtcars)
mtcars[1:5, 2:5] <- NA
M <- cor(mtcars)
corrplot(M, method = 'number', shade.col=NA, tl.col="black", tl.srt=45)

enter image description here

and now check with

M <- cor(mtcars, use = "complete.obs")
corrplot(M, method = 'number', shade.col=NA, tl.col="black", tl.srt=45)

enter image description here

akrun
  • 874,273
  • 37
  • 540
  • 662