options(repos = c(CRAN = "https://cran.r-project.org"))
install.packages("MASS")
## Installing package into 'C:/Users/anton/AppData/Local/R/win-library/4.3'
## (as 'lib' is unspecified)
## Warning: package 'MASS' is not available for this version of R
## 
## A version of this package for your version of R might be available elsewhere,
## see the ideas at
## https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
library(MASS)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
data(survey, package = "MASS")
ExamData <- survey  
str(ExamData)
## 'data.frame':    237 obs. of  12 variables:
##  $ Sex   : Factor w/ 2 levels "Female","Male": 1 2 2 2 2 1 2 1 2 2 ...
##  $ Wr.Hnd: num  18.5 19.5 18 18.8 20 18 17.7 17 20 18.5 ...
##  $ NW.Hnd: num  18 20.5 13.3 18.9 20 17.7 17.7 17.3 19.5 18.5 ...
##  $ W.Hnd : Factor w/ 2 levels "Left","Right": 2 1 2 2 2 2 2 2 2 2 ...
##  $ Fold  : Factor w/ 3 levels "L on R","Neither",..: 3 3 1 3 2 1 1 3 3 3 ...
##  $ Pulse : int  92 104 87 NA 35 64 83 74 72 90 ...
##  $ Clap  : Factor w/ 3 levels "Left","Neither",..: 1 1 2 2 3 3 3 3 3 3 ...
##  $ Exer  : Factor w/ 3 levels "Freq","None",..: 3 2 2 2 3 3 1 1 3 3 ...
##  $ Smoke : Factor w/ 4 levels "Heavy","Never",..: 2 4 3 2 2 2 2 2 2 2 ...
##  $ Height: num  173 178 NA 160 165 ...
##  $ M.I   : Factor w/ 2 levels "Imperial","Metric": 2 1 NA 2 2 1 1 2 2 2 ...
##  $ Age   : num  18.2 17.6 16.9 20.3 23.7 ...
missing_rows <- complete.cases(ExamData)
ExamData2 <- ExamData[missing_rows, ]
FilteredData <- ExamData2[, c("Sex", "W.Hnd", "Height", "Age", "Smoke")]
FilteredData <- FilteredData[order(FilteredData$Age, decreasing = TRUE), ]
ggplot(FilteredData, aes(x = Age, fill = Sex)) + geom_bar() + labs(title = "Age vs Sex", x = "Age", y = "Count") + theme_minimal()