# NOT RUN {
# Generate data for the example
carseats <- ISLR::Carseats
carseats[sample(seq(NROW(carseats)), 20), "Income"] <- NA
carseats[sample(seq(NROW(carseats)), 5), "Urban"] <- NA
# Visualize correlation plot of all numerical variables
plot_correlate(carseats)
# Select the variable to compute
plot_correlate(carseats, Sales, Price)
plot_correlate(carseats, -Sales, -Price)
plot_correlate(carseats, "Sales", "Price")
plot_correlate(carseats, 1)
# Using dplyr::grouped_dt
library(dplyr)
gdata <- group_by(carseats, ShelveLoc, US)
plot_correlate(gdata, "Sales")
plot_correlate(gdata)
# Using pipes ---------------------------------
# Visualize correlation plot of all numerical variables
carseats %>%
plot_correlate()
# Positive values select variables
carseats %>%
plot_correlate(Sales, Price)
# Negative values to drop variables
carseats %>%
plot_correlate(-Sales, -Price)
# Positions values select variables
carseats %>%
plot_correlate(1)
# Positions values select variables
carseats %>%
plot_correlate(-1, -2, -3, -5, -6)
# Using pipes & dplyr -------------------------
# Visualize correlation plot of 'Sales' variable by 'ShelveLoc'
# and 'US' variables.
carseats %>%
group_by(ShelveLoc, US) %>%
plot_correlate(Sales)
# Extract only those with 'ShelveLoc' variable level is "Good",
# and visualize correlation plot of 'Sales' variable by 'Urban'
# and 'US' variables.
carseats %>%
filter(ShelveLoc == "Good") %>%
group_by(Urban, US) %>%
plot_correlate(Sales)
# }
Run the code above in your browser using DataLab