title: implementation of the Gower distance function
body: <p>I have a matrix (size: 28 columns and 47 rows) with numbers. This matrix has an extra row that is contains headers for the columns ("ordinal" and "nominal").</p>
  
  <p>I want to use the Gower distance function on this matrix. <a href="http://rgm2.lab.nig.ac.jp/RGM2/R_man-2.9.0/library/StatMatch/man/gower.dist.html" rel="nofollow">Here</a> says that:</p>
  
  <p><strong>The final dissimilarity between the ith and jth units is obtained as a weighted sum of dissimilarities for each variable:</strong></p>
  
  <pre><code>    d(i,j) = sum_k(delta_ijk * d_ijk ) / sum_k( delta_ijk )
  </code></pre>
  
  <p>In particular, d_ijk represents the distance between the ith and jth unit computed considering the kth variable. It depends on the nature of the variable:</p>
  
  <ul>
  <li><p>factor or character columns are
  considered as categorical nominal
  variables and <code>d_ijk = 0</code> if </p>
  
  <p>x_ik =x_jk, 1 otherwise;</p></li>
  <li><p>ordered columns are considered as
  categorical ordinal variables and<br>
  the values are substituted with the<br>
  corresponding position index, r_ik in
  the factor levels. These position<br>
  indexes (that are different from the 
  output of the R function rank) are<br>
  transformed in the following manner</p></li>
  </ul>
  
  <p>z_ik = (r_ik - 1)/(max(r_ik) - 1)</p>
  
  <p>These new values, z_ik, are treated as observations of an<br>
     interval scaled variable.</p>
  
  <p>As far as the weight delta_ijk is concerned:</p>
  
  <ul>
  <li>delta_ijk = 0 if x_ik = NA or x_jk =
  NA;</li>
  <li>delta_ijk = 1 in all the other cases.</li>
  </ul>
  
  <p>I know that there is a gower.dist function, but I must do it that way. 
  So, for "d_ijk", "delta_ijk" and "z_ik", I tried to make functions, as I didn't find a better way.</p>
  
  <p>I started with "delta_ijk" and i tried this:</p>
  
  <pre><code>Delta=function(i,j){for (i in 1:28){for (j in 1:47){  
  +{if (MyHeader[i,j]=="nominal")
  + result=0
  +{else if (MyHeader[i,j]=="ordinal") result=1}}}}
  +;result}
  </code></pre>
  
  <p>But I got error. So I got stuck and I can't do the rest. </p>
  
  <p>P.S. Excuse me if I make mistakes, but English is not a language I very often.</p>