Solution: Clean Data
Explore the solution to the "Clean Data" challenge and compare it to your answer.
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 typemutate(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 conditionsselect(age)%>% # Select the `age` columnsum() # Calculate the total age# ------#Please name the desired output as 'result'cat(result)}
Get hands-on with 1200+ tech skills courses.