title: Why daisy() in cluster library failed to exclude NA when computing dissimilarity
body: <p>According to <code>daisy</code> function from <code>cluster</code> <a href="http://stat.ethz.ch/R-manual/R-devel/library/cluster/html/daisy.html" rel="nofollow">documentation</a>,
  it can compute dissimilarity when NA (missing) value(s) is present.</p>
  
  <blockquote>
    <p>In the daisy algorithm, missing values in a row of x are not included
    in the dissimilarities involving that row. There are two main cases,</p>
    
    <p>If all variables are interval scaled (and metric is not "gower"), the
    metric is "euclidean", and n_g is the number of columns in which
    neither row i and j have NAs, then the dissimilarity d(i,j) returned
    is sqrt(p/n_g) (p=ncol(x)) times the Euclidean distance between the
    two vectors of length n_g shortened to exclude NAs. The rule is
    similar for the "manhattan" metric, except that the coefficient is
    p/n_g. If n_g = 0, the dissimilarity is NA.</p>
    
    <p>When some variables have a type other than interval scaled, or if
    metric = "gower" is specified, the dissimilarity between two rows is
    the weighted mean of the contributions of each variable. Specifically,</p>
    
    <p>d_ij = d(i,j) =   sum(k=1:p; w_k delta(ij;k) d(ij,k)) / sum(k=1:p; w_k
    delta(ij;k)).</p>
    
    <p>In other words, d_ij is a weighted mean of d(ij,k) with weights w_k
    delta(ij;k), where w_k= weigths[k], delta(ij;k) is 0 or 1, and
    d(ij,k), the k-th variable contribution to the total distance, is a
    distance between x[i,k] and x[j,k], see below.</p>
    
    <p>The 0-1 weight delta(ij;k) becomes zero when the variable x[,k] is
    missing in either or both rows (i and j), or when the variable is
    asymmetric binary and both values are zero. In all other situations it
    is 1.</p>
    
    <p>The contribution d(ij,k) of a nominal or binary variable to the total
    dissimilarity is 0 if both values are equal, 1 otherwise. The
    contribution of other variables is the absolute difference of both
    values, divided by the total range of that variable. Note that
    “standard scoring” is applied to ordinal variables, i.e., they are
    replaced by their integer codes 1:K. Note that this is not the same as
    using their ranks (since there typically are ties).</p>
    
    <p>As the individual contributions d(ij,k) are in [0,1], the
    dissimilarity d_ij will remain in this range. If all weights w_k
    delta(ij;k) are zero, the dissimilarity is set to NA.</p>
  </blockquote>
  
  <p>But why when I tried this code </p>
  
  <pre><code>library(cluster)
  x &lt;- c(1.115,NA,NA,0.971,NA)
  y &lt;- c(NA,1.006,NA,NA,0.645)
  #z &lt;- c(1.115,1.3,2.2,0.971,NA)
  df &lt;- as.data.frame(rbind(x,y))
  daisy(df,metric="gower")
  </code></pre>
  
  <p>It gave this message:</p>
  
  <pre><code>Dissimilarities :
     x
  y NA
  
  Metric :  mixed ;  Types = I, I, I, I, I 
  Number of objects : 2
  Warning messages:
  1: In min(x) : no non-missing arguments to min; returning Inf
  2: In max(x) : no non-missing arguments to max; returning -Inf
  </code></pre>
  
  <p>I expect the dissimilarity output gives a non-NA value e.g. 0.
  What's the right way to do it?</p>
  
  <p>How can I replace the NA from <code>daisy()</code> output with 0?</p>