###Fifty pro-football rookies were rated on a scale of 1 to 5, based on performance at a training camp as well as on past performance. A ranking of 1 indicated a poor prospect whereas a ranking of 5 indicated an excellent prospect. The following frequency distribution was constructed.
###a-1. How many of the rookies received a rating of 4 or better?
rating = c(1, 2, 3, 4, 5)
freq = c(4, 10, 14, 18, 4)
myData = data.frame(Rating=rating, Frequency =freq)
rookie1 = myData[which(myData$Rating >= 4),]
n=colSums(rookie1)
sprintf("%s rookies scored 4 or better.", n[2])
## [1] "22 rookies scored 4 or better."
## [1] "14 rookies scored 2 or less."
###b-1. Construct the corresponding relative frequency distribution. (Round your answers to 2 decimal places.)
n = colSums(myData)
total = n[2]
myData["RelFreq"] = myData$Frequency/total
myData
## Rating Frequency RelFreq
## 1 1 4 0.08
## 2 2 10 0.20
## 3 3 14 0.28
## 4 4 18 0.36
## 5 5 4 0.08
###b-2. What percent received a rating of 5?
rookie3 = myData[which(myData$Rating == 5),]
n=rookie3[1, 3]*100
sprintf("%s percent received a rating of 5.", n)
## [1] "8 percent received a rating of 5."
###c. Construct a bar chart for this data. (Before plotting the points, round the “Relative Frequency” to 2 decimal places. Click on the x-axis exactly below the “0” point and then drag the bar till it reaches the correct answer.)
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.0.5
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.3 v purrr 0.3.4
## v tibble 3.1.2 v dplyr 1.0.6
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## Warning: package 'ggplot2' was built under R version 4.0.5
## Warning: package 'tibble' was built under R version 4.0.5
## Warning: package 'tidyr' was built under R version 4.0.5
## Warning: package 'readr' was built under R version 4.0.5
## Warning: package 'purrr' was built under R version 4.0.5
## Warning: package 'dplyr' was built under R version 4.0.5
## Warning: package 'stringr' was built under R version 4.0.5
## Warning: package 'forcats' was built under R version 4.0.5
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
ggplot(myData, aes(Rating, RelFreq))+
geom_bar(stat = "identity", color="blue", fill="cadetblue1")+
geom_text(aes(label=RelFreq), vjust=-0.3, size=5)+
labs(title = "Ratings of Pro Football Rookies",
x ="Rating",
y = "Relative Frequency", size =5)