I'm hoping how I word this isn't too confusing. The dataset that I am using has recorded respondents' marital and years of school attended (degree). I would like to create a measure that corresponds to the highest degree of a caregiver living in the household.
My variables look like this:
0 = single, never married
1 or 2 = partner in the house, use higher degree between maternal highest degree or partner highest degree
3:7 = single-parent household, therefore use the maternal highest degree
# sample dataframe
household <- data.frame(
  ID = c(1, 2, 3, 4),
  marital = c(1, 4, 0, 2),
  education = c(14, 18, 10, 12),
  education_partner = c(18, NA, NA, 14)
)
I'm hoping to create a new column at the end of my data frame for the highest degree of a caregiver living in the home
Expected output:
ID    marital    education    education_partner    highest_degree     
1        1          14              18                  18     
2        4          18              NA                  18
3        0          10              NA                  10
4        2          12              14                  14
I tried to write this code to print the maternal education if it's a single parent household, but I don't know how to make it choose the higher of the two if its a 2 parent household (marital = 1 or 2). and I'm not even sure if an if, then statement would best help me. I'm new to learning R so any help is greatly appreciated -- thank you in advance!
if(household$marital =  0 | 3:7 )
  highest_degree<- (household$education)
 
     
     
     
    