title: How to use 'hclust' as function call in R
body: <p>I tried to construct the clustering method as function the following ways:</p>
  
  <pre><code>mydata &lt;- mtcars
  
  # Here I construct hclust as a function
  hclustfunc &lt;- function(x) hclust(as.matrix(x),method="complete")
  
  # Define distance metric
  distfunc &lt;- function(x) as.dist((1-cor(t(x)))/2)
  
  # Obtain distance
  d &lt;- distfunc(mydata)
  
  # Call that hclust function
  fit&lt;-hclustfunc(d)
  
  # Later I'd do
  # plot(fit)
  </code></pre>
  
  <p>But why it gives the following error:</p>
  
  <pre><code>Error in if (is.na(n) || n &gt; 65536L) stop("size cannot be NA nor exceed 65536") : 
    missing value where TRUE/FALSE needed
  </code></pre>
  
  <p>What's the right way to do it?</p>