[R] Error message NA/NaN/Inf in foreign function call (arg 6) when using knn()
Kerri-Ann Norton
kerrin at eden.rutgers.edu
Wed Jul 6 17:29:12 CEST 2005
I am trying to use knn to do a nearest neighbor classification. I tried using my dataset and got an error message so I used a simple example to try and understand what I was doing wrong and got the same message. Here is what I typed into R:
try
[,1] [,2] [,3] [,4]
r "A" "A" "T" "G"
r "A" "A" "T" "G"
f "A" "A" "c" "G"
f "A" "A" "c" "G"
f "A" "A" "c" "G"
> cl2 <-factor(c(rep("1",2), rep("2",3)))
> cl2
[1] 1 1 2 2 2
Levels: 1 2
> knn(try, try, cl2, k = 2)
Error in knn(try, try, cl2, k = 2) : NA/NaN/Inf in foreign function call (arg 6)
In addition: Warning messages:
1: NAs introduced by coercion
2: NAs introduced by coercion
I used try as test and train because I thought the error might be that the size of test and train data were different. If someone could explain what the error means or how to fix it, I would greatly appreciate it.
Kerri-Ann Norton
More information about the R-help
mailing list