title: How to create and insert a column with categorical variables for specific ranges
body: <p>I have a dataframe with over a thousand rows with very long sample names and therefore wanted to add a categorical index.</p>
  
  <p>For example to this dataframe:</p>
  
  <pre><code>sample               ...
  Br_LV_0040324_BC1_1  ...
  Br_LV_0040324_BC1_2  ...
  Br_LV_0040324_BC1_3  ...
  Br_LV_0040324_BC1_4  ...
  Br_LV_0040324_LBR_1  ...
  Br_LV_0040324_LBR_2  ...
  </code></pre>
  
  <p>add a categorical index so it looks like:</p>
  
  <pre><code>Index   sample               ...
  BC1     Br_LV_0040324_BC1_1  ...
  BC1     Br_LV_0040324_BC1_2  ...
  BC1     Br_LV_0040324_BC1_3  ...
  LBR     Br_LV_0040324_LBR_4  ...
  LBR     Br_LV_0040324_LBR_1  ...
  LBR     Br_LV_0040324_LBR_2  ...
  </code></pre>
  
  <p>I ended up counting the number of groups by eye and figured I could just create a dataframe with the same amount of levels as my data and then assign labels by range, manually. So I tried</p>
  
  <pre><code>s1 &lt;- sample(0:1, 1022, replace = TRUE)
  Index &lt;- as.data.frame(s1, labels = "yes")
  Index[1:32,1] &lt;- "BC1"
  Index[33:88,1] &lt;- "LBR"
  ...
  Index &lt;- Index[,-2]
  </code></pre>
  
  <p>It worked, but I'm sure there has to be some easier way than using this convoluted method and also counting the ranges by eye!</p>