title: find number of clusters in hierarchical clustering dendrogram after cutree in r
body: <p>Here I have some problem to find number of clusters after using cutree on a dendrogram. Here is my approach:</p>
  
  <pre><code>mat &lt;- a huge matrix
  hc &lt;- (as.dist(mat), method = "average", members = NULL)  
  #to cut the tree just 1 level below the maximum height
  tree &lt;- cutree(hc, h = hc$height[[length(hc$height)-1]])  
  </code></pre>
  
  <p>By printing the tree variable I can see that my dendrogram is cut into two clusters. I can also get the labels from each cluster using names(tree[tree==1]), but how can get the number of clusters without looking at the data? I want to automate this in a pipeline based on number of clusters it has in tree variable.</p>