impute.age <- function(age, sex){
corrected.age <- age
if(is.na(age) & sex == 1){
corrected.age <- male.mean.age
}else if(is.na(age) & sex == 0){
corrected.age <- female.mean.age
}else{
return(corrected.age)
}
}
I wrote this function, and this doesn't seem to be working. Is there any other ways where I can fill NA values in the Age column with the mean of value of Ages based on sexes (Male and Female)