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

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Sat 09 Jul 2005 - 02:05:20 EST

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@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



R-help@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 Received on Sat Jul 09 02:11:58 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:25 EST