title: Why do we get error saying "train" and "class" have different lengths while using Knn function in R?
body: <p>I know this question has been asked before, I have checked other portals but didn't get the correct response.</p>
  
  <p>I was doing a school project following a sample manual based on the medical records.</p>
  
  <p>So I begin with splitting the data set into two parts test and train.
  There are 569 records and 31 variables : </p>
  
  <p>Wbcd_train : 469 obj. 31 Var.</p>
  
  <p>Wbcd_test : 100 obj. 31 Var.</p>
  
  <p>Wbcd_train_lables : 469 obj. 1 Var.</p>
  
  <p>Adding sample data entries for wbcd_train, wbcd_test, wncd_train_lables.</p>
  
  <p><strong>wbcd_train</strong> :</p>
  
  <p><strong>Radius</strong>  17.99 <strong>Texture</strong>  10.38 <strong>Perimeter</strong>  122.8 <strong>Area</strong>  0.1184</p>
  
  <p><strong>wbcd_test</strong> :</p>
  
  <p><strong>Radius</strong>  17.6   <strong>Texture</strong>  23.33  <strong>Perimeter</strong>  119  <strong>Area</strong>  980.5  </p>
  
  <p><strong>wncd_train_lables</strong> :</p>
  
  <p><strong>Diagnosis</strong> M</p>
  
  <p>When using the function :</p>
  
  <pre><code>wbcd_test_pred &lt;- knn(train = wbcd_train, test = wbcd_test, cl = wbcd_train_labels, k = 21)
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
  <pre><code>knn(train = wbcd_train, test = wbcd_test, cl = wbcd_train_labels,  : 
    'train' and 'class' have different lengths
  </code></pre>
  </blockquote>