0 votes
in R Basics by

Can you write me a function in R that replaces all missing values of a vector with the mean of that vector?

1 Answer

0 votes
by

mean_impute <- function(x) { x[is.na(x)] <- mean(x, na.rm = TRUE); x }

...