Question: R Studio - Programming / Statistics I am trying to create a new variable 'child_or_adult' in my data set 'titanic', by using mutate() and ifelse().

R Studio - Programming / Statistics

I am trying to create a new variable 'child_or_adult' in my data set 'titanic', by using mutate() and ifelse(). The new variable would specify the age group of each person. However, the variable 'age' contains NAs values, which I don't want to ignore. Instead, I want to classify them as 'adult'. How could I do this by using is.na() within the ifeslse() statement ?

titanic %>% mutate(child_or_adult = ifelse(test = age <= 9, yes = "child", no = "adult", is.na(age) <- "adult" )) 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!