Solution: Clean Data

Explore the solution to the "Clean Data" challenge and compare it to your answer.

Press + to interact
library(dplyr)
clean_data <- function(x){
# Code between the dashed lines
# ------
result <- infert %>% mutate(case = as.logical(case))%>% # Convert the `case` column into logical data type
mutate(age_status = ifelse(age >= mean(age),'AA','BA'))%>% # Create a new age column showing 'BA' if the age is below average otherwise it shows 'AA'
filter(age_status =='BA' & case == TRUE & parity >= 4)%>% # Filter the columns by the conditions
select(age)%>% # Select the `age` column
sum() # Calculate the total age
# ------
#Please name the desired output as 'result'
cat(result)
}

Get hands-on with 1400+ tech skills courses.