library(ISLR)
data(Auto)
Auto <- na.omit(Auto)
quantitative_vars <- c("mpg", "cylinders", "displacement", "horsepower", "weight", "acceleration", "year")
qualitative_vars <- c("origin", "name")
cat("Quantitative Variables:", paste(quantitative_vars, collapse = ", "), "\n")
## Quantitative Variables: mpg, cylinders, displacement, horsepower, weight, acceleration, year
cat("Qualitative Variables:", paste(qualitative_vars, collapse = ", "))
## Qualitative Variables: origin, name
sapply(Auto[quantitative_vars], range, na.rm = TRUE)
## mpg cylinders displacement horsepower weight acceleration year
## [1,] 9.0 3 68 46 1613 8.0 70
## [2,] 46.6 8 455 230 5140 24.8 82
sapply(Auto[quantitative_vars], function(x) c(Mean = mean(x, na.rm = TRUE), SD = sd(x, na.rm = TRUE)))
## mpg cylinders displacement horsepower weight acceleration
## Mean 23.445918 5.471939 194.412 104.46939 2977.5842 15.541327
## SD 7.805007 1.705783 104.644 38.49116 849.4026 2.758864
## year
## Mean 75.979592
## SD 3.683737
Auto_new <- Auto[-(10:85), ]
sapply(Auto_new[quantitative_vars], range, na.rm = TRUE)
## mpg cylinders displacement horsepower weight acceleration year
## [1,] 11.0 3 68 46 1649 8.5 70
## [2,] 46.6 8 455 230 4997 24.8 82
sapply(Auto_new[quantitative_vars], function(x) c(Mean = mean(x, na.rm = TRUE), SD = sd(x, na.rm = TRUE)))
## mpg cylinders displacement horsepower weight acceleration
## Mean 24.404430 5.373418 187.24051 100.72152 2935.9715 15.726899
## SD 7.867283 1.654179 99.67837 35.70885 811.3002 2.693721
## year
## Mean 77.145570
## SD 3.106217
pairs(Auto[quantitative_vars])

par(mfrow = c(2, 2))
plot(Auto$horsepower, Auto$mpg, main = "MPG vs Horsepower", xlab = "Horsepower", ylab = "MPG", col = "blue")
plot(Auto$weight, Auto$mpg, main = "MPG vs Weight", xlab = "Weight", ylab = "MPG", col = "red")
plot(Auto$displacement, Auto$mpg, main = "MPG vs Displacement", xlab = "Displacement", ylab = "MPG", col = "green")
plot(Auto$acceleration, Auto$mpg, main = "MPG vs Acceleration", xlab = "Acceleration", ylab = "MPG", col = "purple")
