title: K nearest neighbors with Gower distance measure in R
body: <p>I hope everyone is well; I have a question it is may be looked as a dumb one  but I really need someone to explain it for me. I  also though it will be useful for some, since it has been asked before with no satisfactory answer. </p>
  
  <p>Since , I have mixed data type matrix, I was looking for K-nearst neighbors algorithem that works with gower distance in R. I found the function <strong>Knngow</strong>  under the package <strong>dprep</strong> that claims to perform this. 
  <a href="http://finzi.psych.upenn.edu/library/dprep/html/knngow.html" rel="nofollow">http://finzi.psych.upenn.edu/library/dprep/html/knngow.html</a></p>
  
  <p>The function take three argument  knngow( Training_Set, Testing_set, K_number) and return the predicted class.</p>
  
  <p>I was playing around with it and was wondering how the function can recognize what is my target vector?  Put differently, how does it return the predicted class, without me acknowledging it in advance with my target column. </p>
  
  <p>please find the source code below ( I retrieved it using the function <strong>edit</strong>)</p>
  
  <pre><code>function (train, test, k) 
  {
      p = dim(train)[2]
      ntest = dim(test)[1]
      ntrain = dim(train)[1]
      classes = rep(0, ntest)
      if (ntest == ntrain) {
          for (i in 1:ntest) {
              tempo = order(gower.dist(test[i, -p], train[-i, 
                  -p]))[1:k]
              classes[i] = moda(train[tempo, p])[1]
          }
      }
      else {
          for (i in 1:ntest) {
              tempo = order(StatMatch::gower.dist(test[i, -p], 
                  train[, -p]))[1:k]
              classes[i] = moda(train[tempo, p])[1]
          }
      }
      classes
  }
  </code></pre>
  
  <p>please can someone explain for me the code?</p>
  
  <p>I hope I have post the question in the correct form, please let me know if I have to move it to somewhere else.</p>
  
  <p>Thank you very much for your time.</p>