Search code examples
rmatrixnapearson-correlation

Correlation matrix correlations in R shown as "?" in the grid


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


Solution

  • 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