I have this vector:
a<-c(1,2,3,NA,4,5,NA,NA,100,45,NA)
and I'm trying to replace all the missing values present in this vector by writing this custom function:
mean_impute<-function(x){
ifelse(is.na(x),mean(x),x)
}
But the result obtained has NA values in it. What is wrong with this function?