Chapter 4 problem 1

Author

Schwab

You can copy the code below (just the gray boxes) to make the Random_subset from the book

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.2.1      ✔ stringr 1.4.1 
✔ readr   2.1.2      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(mdsr)
library(babynames)

#This makes the Random_subset

Random_subset <- babynames %>%
  filter(year=="2003" & name=="Bilal" & sex =="M" |year=="1999" & name=="Terria" & sex =="F" |year=="2010" & name=="Naziyah" & sex =="F" |year=="1989" & name=="Shawana" & sex =="F" |year=="1989" & name=="Jessi" & sex =="F" |year=="1928" & name=="Tillman" & sex =="M"|year=="1981" & name=="Leslee" & sex =="F" |year=="1981" & name=="Sherise" & sex =="F"|year=="1920" & name=="Marquerite" & sex =="F" |year=="1941" & name=="Lorraine" & sex =="M") 

Below is how I would answer part a.

# I'll do the first one for you. There may be other solutions.

Random_subset %>% filter( n>40 & n<85) 
# A tibble: 4 × 5
   year sex   name        n      prop
  <dbl> <chr> <chr>   <int>     <dbl>
1  1928 M     Tillman    43 0.0000377
2  1981 F     Leslee     83 0.0000464
3  1989 F     Shawana    41 0.0000206
4  2010 F     Naziyah    45 0.0000230