if (!require(corrplot)) install.packages("corrplot", repos = "http://cran.us.r-project.org")
## Loading required package: corrplot
## corrplot 0.95 loaded
library(corrplot)
if (all(sapply(df, is.numeric))) {  
    corr_matrix <- cor(df, use = "complete.obs")  
    library(corrplot)  
    corrplot(corr_matrix, method = "color", type = "upper", tl.cex = 0.8)  
} else {  
    print("Error")  
}  
## [1] "Error"

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

lapply(df, summary)
## $x
## Length  Class   Mode 
##      1   name   name 
## 
## $df1
## Length  Class   Mode 
##      1   name   name 
## 
## $df2
## Length  Class   Mode 
##      1   name   name 
## 
## $ncp
## Length  Class   Mode 
##      1   name   name 
## 
## $log
##    Mode   FALSE 
## logical       1 
## 
## [[6]]
## Length  Class   Mode 
##      2      {   call
print(head(df))  
##                                               
## 1 function (x, df1, df2, ncp, log = FALSE)    
## 2 {                                           
## 3     if (missing(ncp))                       
## 4         .Call(C_df, x, df1, df2, log)       
## 5     else .Call(C_dnf, x, df1, df2, ncp, log)
## 6 }
class(df)
## [1] "function"
str (df)
## function (x, df1, df2, ncp, log = FALSE)
df <- read.csv("Housing.csv", header = TRUE, stringsAsFactors = FALSE)
df[] <- lapply(df, function(x) if(is.character(x)) as.numeric(as.factor(x)) else x)

Scatter Plots

## [1] "Error: Kolom X1 atau X2 tidak ditemukan dalam df."
if (all(sapply(df, is.numeric))) {  
    corr_matrix <- cor(df, use = "complete.obs")  
    library(corrplot)
    corrplot(corr_matrix, method = "color", type = "upper", tl.cex = 0.8)  
} else {  
    print("Error: Pastikan semua kolom numerik sebelum menghitung korelasi.")  
}  

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.