I am trying to impute the dataframe with Hmisc impute model. I am able to impute the data for one column at a time but fail to loop over columns.
Below example - works fine but I would like to make it dynamic using a function:
impute_marks$col1 <- with(impute_marks, round(impute(col1, mean)),0)
Example:
impute_dataframe <- function()
{
for(i in 1:ncol(impute_marks))
{
impute_marks[is.na(impute_marks[,i]), i] <- with(impute_marks, round(impute(impute_marks[,i], mean)),0)
}
}
impute_dataframe
There is no error when I run the function but there is no imputed data as well to the dataset impute_marks.