After I wrote up the exercises and created the video, the folks at Openintro changed the name of the variable giving the father’s age from fAge to f_age. Therefore, the existing code is incorrect.

library(openintro)
## Loading required package: airports
## Loading required package: cherryblossom
## Loading required package: usdata
str(births)
## tibble [150 × 9] (S3: tbl_df/tbl/data.frame)
##  $ f_age    : int [1:150] 31 34 36 41 42 37 35 28 22 36 ...
##  $ m_age    : int [1:150] 30 36 35 40 37 28 35 21 20 25 ...
##  $ weeks    : int [1:150] 39 39 40 40 40 40 28 35 32 40 ...
##  $ premature: Factor w/ 2 levels "full term","premie": 1 1 1 1 1 1 2 2 2 1 ...
##  $ visits   : int [1:150] 13 5 12 13 NA 12 6 9 5 13 ...
##  $ gained   : int [1:150] 1 35 29 30 10 35 29 15 40 34 ...
##  $ weight   : num [1:150] 6.88 7.69 8.88 9 7.94 8.25 1.63 5.5 2.69 8.75 ...
##  $ sex_baby : Factor w/ 2 levels "female","male": 2 2 2 1 2 2 1 1 2 1 ...
##  $ smoke    : Factor w/ 2 levels "nonsmoker","smoker": 2 1 1 1 1 2 1 2 2 1 ...

Exercise 3 Correction

Note how I changed fAge to f_age

births$Father = ifelse(is.na(births$f_age),"Absent","Present")
table(births$Father)
## 
##  Absent Present 
##      31     119