title: R Univariate Clustering by Group
body: <p>I am trying to find a method to cluster univariate data by group. For example, in the data below I have two failure codes (a and b) and 6 data points for each grouping. In the plot you can see that for each failure code there are 2 distinct clusters for failure time. Manually this isn't bad, but I can't figure out how to do this with a larger data set (~100K rows and ~30 codes). I would like for the end result to give me the medoid for each cluster and the count of codes in that cluster.</p>
  
  <pre><code>library(ggplot2)
  failure &lt;- rep(c("a","b"),each=6)
  ttf &lt;- c(1,1.5,2,5,5.5,6,8,8.5,9,14,14.5,15)
  data &lt;- data.frame(failure,ttf)
  qplot(failure, ttf)
  results &lt;- data.frame(failure = c("a","b"), m1 = c(1.5,8.5), m2 = c(5.5,14.5))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/dpoWX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dpoWX.png" alt="enter image description here"></a></p>
  
  <p>I would like for the end result to give me something like the table below.</p>
  
  <pre><code>failure m1   m1count  m2    m2count
  a       1.5  3        5.5   3
  b       8.5  3        14.5  3
  </code></pre>