title: Add a column with pre-assigned treatment value to specific ID for each row in R
body: <p>I have 24 csv files with some raw data that I am trying to wrangle so I can analyse it. The raw data has a 'group' number 1-65 (the number of a plant - an ID number) and some measurements - Chl, Flav, Anth, NBI. I am trying to assign back the specific treatment to the specific plant - treatments ABCDE. This would be fine if each plant had only one measurement as they are always in sequence, but there are varying amounts of measurements for each plant(group). How can I loop over the data frame so that it adds a column of treatments that correspond to the correct group number? I know I have to write the <code>if (group == 1) {table$treatment &lt;- 'B'}</code> (or something that actually is functioning code because I don't know if that would work) for each of the specific groups but that'll still be faster than doing it manually, as I can just apply the same code to the other 24 datasets.</p>
  <p>I imagined it would be something like:</p>
  <pre><code>X4_08_11_2020all[,&quot;treatment&quot;] &lt;- NA
  
  treatments &lt;- function(table, col) {
    for (i in rownames(table)) {
      if (col == 1) {table$treatment &lt;- 'B'}
      else if (table$col == 2) {table$treatment &lt;- 'C'}
    }
  }
  
  treatments(X4_08_11_2020all, X4_08_11_2020all$group)
  </code></pre>
  <p>or</p>
  <pre><code>for (i in rownames(X4_08_11_2020all)) {
    if (X4_08_11_2020all$group == 1) {X4_08_11_2020all$treatment &lt;- 'B'}
    else if (X4_08_11_2020all$group == 2) {X4_08_11_2020all$treatment &lt;- 'C'}
  }
  </code></pre>
  <p>But I don't really know.</p>
  <p>The dataset that I'm using is:</p>
  <p><img src="https://filebin.net/9q3vhnxie9xunf73" alt="here" /></p>
  <p>Here is an image of what I would like it to do:</p>
  <p><img src="https://i.stack.imgur.com/OVJRM.jpg" alt="here" /></p>