title: Error in knn: NA/NaN/Inf in foreign function call (arg 6) and warinings about NAs being introduced by coercion
body: <p>I've been asked to apply <code>knn</code> to data for "income", based on "age", "gender" and "occupation" from the adults.txt data. This is my code after loading the data into R.</p>
  
  <pre><code>library(class)
  set.seed(1234)
  ind &lt;- sample(2, nrow(adult), replace=TRUE, prob=c(0.75, 0.25))
  adult.training &lt;- adult[ind==1, c(1,7,10)]
  adult.test &lt;- adult[ind==2, c(1,7,10)]
  adult.trainLabels &lt;- adult[ind==1, c(15)]
  adult.testLabels &lt;- adult[ind==2, c(15)]
  adult_pred &lt;- knn(train=adult.training, test=adult.test, cl=adult.trainLabels, k=3)
  </code></pre>
  
  <p>I get the following errors: </p>
  
  <pre><code>Error in knn(train=adult.training, test=adult.test, cl=adult.trainLabels, :
  NA/NAN/Inf in foreign function call (arg 6)
  In addition: Warning messages:
  1: In knn(train=adult.training, test=adult.test, cl=adult.trainLabels, :
  NAs introduced by coercion
  2: In knn(train=adult.training, test=adult.test, cl=adult.trainLabels, :
  NAs introduced by coercion`
  </code></pre>
  
  <p>Is it possible to generate <code>knn</code> data for "income" based on the above variables two of which are factors?</p>