[R] Error message NA/NaN/Inf in foreign function call (arg 6) when using knn()

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Jul 8 18:05:20 CEST 2005


Kerri-Ann Norton wrote:

> 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
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


What is the euclidean distance between "c" and "T"?

I think this is a user error which the code does not intercept with a 
nice error message.

Uwe Ligges




More information about the R-help mailing list