Install Libraries:

#install.packages("xlsx")
#install.packages("corrgram")
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_221')
library(xlsx)
library(ggplot2)
library(corrgram)
## Registered S3 method overwritten by 'seriation':
##   method         from 
##   reorder.hclust gclus

read xlsx file’s sheet Ex1

df1 <- read.xlsx('E:\\R-Files\\Covar-Correll.xlsx', sheetName="Ex1", header=TRUE, colClasses=NA)
vCor <- cor(df1)
vCor
##         Hits Revenue NA. NA..1
## Hits       1      NA  NA    NA
## Revenue   NA       1  NA    NA
## NA.       NA      NA   1    NA
## NA..1     NA      NA  NA     1
corrgram(df1, order=TRUE)

read xlsx file’s sheet Ex2

df2 <- read.xlsx('E:\\R-Files\\Covar-Correll.xlsx', sheetName="Ex2", header=TRUE, colClasses=NA)
res <- cor(df2)
round(res, 2)
##         Hits Revenue
## Hits       1      NA
## Revenue   NA       1
corrgram(df2, order=TRUE)

read xlsx file’s sheet Ex3

df3 <- read.xlsx('E:\\R-Files\\Covar-Correll.xlsx', sheetName="Ex3", header=TRUE, colClasses=NA)
res <- cor(df3)
round(res, 2)
##         Hits Revenue
## Hits       1      NA
## Revenue   NA       1
corrgram(df3, order=TRUE)

read xlsx file’s sheet Ex4

df4 <- read.xlsx('E:\\R-Files\\Covar-Correll.xlsx', sheetName="Ex4", header=TRUE, colClasses=NA)
res <- cor(df4)
round(res, 2)
##         Hits Revenue
## Hits       1      NA
## Revenue   NA       1
corrgram(df4, order=TRUE)

read xlsx file’s sheet Ex5

df5 <- read.xlsx('E:\\R-Files\\Covar-Correll.xlsx', sheetName="Ex5", header=TRUE, colClasses=NA)
res <- cor(df5)
round(res, 2)
##             Qty.Sold Unit.Price Advertising
## Qty.Sold        1.00      -0.81        0.54
## Unit.Price     -0.81       1.00        0.02
## Advertising     0.54       0.02        1.00
corrgram(df5, order=TRUE)

read xlsx file’S sheet LR1

df6 <- read.xlsx('E:\\R-Files\\Covar-Correll.xlsx', sheetName="LR1", header=TRUE, colClasses=NA)
res <- cor(df6)
round(res, 2)
##                id price sqft_living waterfront view condition
## id           1.00  0.11        0.11      -0.10 0.02      0.06
## price        0.11  1.00        0.67       0.53 0.48      0.05
## sqft_living  0.11  0.67        1.00       0.34 0.20      0.09
## waterfront  -0.10  0.53        0.34       1.00 0.33     -0.01
## view         0.02  0.48        0.20       0.33 1.00      0.17
## condition    0.06  0.05        0.09      -0.01 0.17      1.00
corrgram(df6, order=TRUE)