# 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
# Diagnosis of categorical variables
diagnose_category(carseats)
# Select the variable to diagnose
diagnose_category(carseats, ShelveLoc, Urban)
diagnose_category(carseats, -ShelveLoc, -Urban)
diagnose_category(carseats, "ShelveLoc", "Urban")
diagnose_category(carseats, 7)
# Using pipes ---------------------------------
library(dplyr)
# Diagnosis of all categorical variables
carseats %>%
diagnose_category()
# Positive values select variables
carseats %>%
diagnose_category(Urban, US)
# Negative values to drop variables
carseats %>%
diagnose_category(-Urban, -US)
# Positions values select variables
carseats %>%
diagnose_category(7)
# Positions values select variables
carseats %>%
diagnose_category(-7)
# Top rank levels with top argument
carseats %>%
diagnose_category(top = 2)
# Using pipes & dplyr -------------------------
# Extraction of level that is more than 60% of categorical data
carseats %>%
diagnose_category() %>%
filter(ratio >= 60)
# }
Run the code above in your browser using DataLab