I have used mice package in R to impute some missing values in my data, but not for all variables. Now I would like to replace the columns from the original data with columns from the imputed data, if their column names are equal. Here is my function:
replace_imp <- function(data,impdata) {
for(i in 1:length(impdata)){
for(k in 1:length(data)){
if(colnames(impdata)[i]==colnames(data)[k]){
data[,k] <- imp_data[,i]
}
}
}
}
But it does not seem to work, any help?