Guided Project: Creating An Efficient Data Analysis Workflow, Part 2 Error in replacing missing values with mean

Screen Link: https://app.dataquest.io/m/516/guided-project%3A-creating-an-efficient-data-analysis-workflow%2C-part-2/3/handling-missing-data

My Code:

complete_sales <- complete_sales %>% 
  mutate(
    imputed_purchases = if_else(is.na(total_purchased), 
                                purchase_mean,
                                total_purchased)
  )

What I expected to happen:
A new column named imputed purchases would be created and the NA values would be replaced with the purchase mean.

What actually happened:

Error: Problem with `mutate()` input `imputed_purchases`.
x `false` must be a double vector, not an integer vector.
ℹ Input `imputed_purchases` is `if_else(is.na(total_purchased), purchase_mean, total_purchased)`.

This is literally the code from the solution, and it still will not work for me. I know it is because the if_else function is seeing purchase_mean and total_purchased as two different class types, but how do I fix this? ?

Hello. I ran into the same problem. Changing the if_else() function into ifelse() may help. You will find this link helpful.