I was trying to address the missing values in R through the following code
{ds$bmi=ifelse(is.na(ds$bmi), ave(ds$bmi, Fun=function(x) mean(y,na.rm=TRUE)),ds$bmi)}
it is giving following error
Error in unique.default(x, nmax = nmax) : unique() applies only to vectors
Please help how to address this error