0 votes
in Technology by (1.7m points)

You are solving a data science problem that is ridden with many missing values. You want to clean the data before fitting your model. What would you do to replace these missing values? Develop your own function.

1 Answer

0 votes
by (1.7m points)
Let’s take this vector:

Now, let’s write the function to impute the values:
missing_mean <- function(arr){
ifelse(is.na(arr),mean(arr,na.rm = T),arr)