I am doing regression with a data with Y as target variable and 16 feature variables. I had two date feature variables which where as factor. I converted them to date format as shown below:

X2 <-  as.Date(X2, format="%m/%d/%Y"))

I had a lot of missing data in my training as well as validation data set. I was suggested to try out imputation. R had a lot of packages like AMELIA and Mice.I started trying with Mice package but I am getting the below error.

Error in FUN(newX[, i], ...) : 'x' must be numeric
In addition: Warning message:
In FUN(newX[, i], ...) : NAs introduced by coercion 

Can anyone help me with this error.



closed as off-topic by AdamO, chl Sep 26 '14 at 20:41

  • This question does not appear to be about statistics within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Hi Nikita, you seem to have quite the history of posting software and not statistical related questions on this SE network. Please remember to take questions like these to the appropriate network. $\endgroup$ – AdamO Sep 26 '14 at 20:18
  • 1
    $\begingroup$ Seems like mice was expecting numeric data in a column that didn't have numeric data. The imputation method used by mice depends on the type of data. Check the class of each of your variables, and double-check the arguments you passed to the function. Make sure that you have coded empty values as NA, preferably with the is.na() function to make sure that the class is correct. To troubleshoot, try working with just a few variables at a time. If the problem is in a date column, I agree with the answer provided by @AdamO. $\endgroup$ – EdM Sep 26 '14 at 20:26
  • $\begingroup$ This question appears to be off-topic because it is about R software only. $\endgroup$ – chl Sep 26 '14 at 20:41
  • $\begingroup$ @Adamo Sorry for posting it in the wrong group. Thanks for the answer. $\endgroup$ – Nikita Sinnarkar Sep 26 '14 at 21:00

A better way to approach this problem might be multiple imputation of the missing data, if your data meet the requirements for imputation. The rms package in R provides useful tools for imputation and model validation. You might also want to look at the mice package for the imputation part of the problem; rms can handle objects produced by mice. The web page displaying your question now shows links to other related questions, whose answers might also be useful.


rms is a good package, however, I am not aware of how the imputation was developed in rms and mice has had several publications on the topic.

Nikita, to the best of my knowledge, you must have a character variable in these data. If you are trying to impute date... which is generally a VERY bad idea... then you should convert the date to numeric (as the function of a number of days since Jan 1st 1970, the default numeric date conversion), then rerun the imputation.

Again I stress that imputing date is a poor idea.

  • $\begingroup$ Thanks for the reply. I did convert factor variable to date and them into numeric format and it does work. When I am predicting values I have the missing data in my test set for the date and want to predict for all values irrespective of missing value. That's why I wanted to impute date. $\endgroup$ – Nikita Sinnarkar Sep 26 '14 at 20:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.