title: Cluster sequences of strings in R
body: <p>I have to following data:</p>
  
  <pre><code>attributes &lt;- c("apple-water-orange", "apple-water", "apple-orange", "coffee", "coffee-croissant", "green-red-yellow", "green-red-blue", "green-red","black-white","black-white-purple")
  attributes 
  
             attributes 
  1  apple-water-orange
  2         apple-water
  3        apple-orange
  4              coffee
  5    coffee-croissant
  6    green-red-yellow
  7      green-red-blue
  8           green-red
  9         black-white
  10 black-white-purple
  </code></pre>
  
  <p>What I want is another column, that assigns a category to each row, based on observation similarity. </p>
  
  <pre><code>category &lt;- c(1,1,1,2,2,3,3,3,4,4)
  df &lt;- as.data.frame(cbind(df, category))
  
         attributes     category
  1  apple-water-orange        1
  2         apple-water        1
  3        apple-orange        1
  4              coffee        2
  5    coffee-croissant        2
  6    green-red-yellow        3
  7      green-red-blue        3
  8           green-red        3
  9         black-white        4
  10 black-white-purple        4
  </code></pre>
  
  <p>It is clustering in the broader sense, but I think most clustering methods are for numeric data only and one-hot-encoding has a lot of disadvantages (thats what I read on the internet).</p>
  
  <p>Does anyone have an idea how to do this task? Maybe some word-matching approaches?</p>
  
  <p><strong>It would be also great if I could adjust degree of similarity (rough vs. decent "clustering") based on a parameter.</strong></p>
  
  <p>Thanks in advance for any idea! </p>