KNN imputation and error messages

Dear R Experts

I got the following error messages during the KNN imputation:

#KNN imputation
library(VIM)
?knn()
KNNImputed <- kNN (data1, variable = c("var_1"), k = 20)

>  In `[<-.data.table`(`*tmp*`, indexNA2s[, variable[j]], variable[j],  :
>   Coerced 'double' RHS to 'integer' to match the column's type; may have truncated precision. Either change the target column ['var_1'] to 'double' first (by creating a new 'double' vector length 787 (nrows of entire table) and assign that; i.e. 'replace' column), or coerce RHS to 'integer' (e.g. 1L, NA_[real|integer]_, as.*, etc) to make your intent clear and for speed. Or, set the column type correctly up front when you create the table and stick to it, please.

Thanks for considering my request.

Best wishes
Larry

Could you please turn this into a self-contained reprex (short for reproducible example)? It will help us help you if we can be sure we're all working with/looking at the same stuff.

install.packages("reprex")

If you've never heard of a reprex before, you might want to start by reading the tidyverse.org help page. The reprex dos and don'ts are also useful.

What to do if you run into clipboard problems

If you run into problems with access to your clipboard, you can specify an outfile for the reprex, and then copy and paste the contents into the forum.

reprex::reprex(input = "fruits_stringdist.R", outfile = "fruits_stringdist.md")

For pointers specific to the community site, check out the reprex FAQ.

Thanks for the response Mara. I appreciate it very much. The issue has been solved. Importing data from original Excel (.xslx) or SPSS (.sav).

Cheers
Larry

1 Like

If your question's been answered (even if by you), would you mind choosing a solution? (See FAQ below for how).

Having questions checked as resolved makes it a bit easier to navigate the site visually and see which threads still need help.

Thanks