title: Replace unique values of a column by a vector of new values
body: <p>I have a dataframe with three columns: two to identify the individual, and one that corresponds to the individual's answer to a question. In this example, the answers are coded from 1 to 3 (as characters) and may contain <code>NA</code>. I would like to replace these values with their true meaning. </p>
  
  <pre><code>library(tibble)
  
  my_data &lt;- tibble(
    first_id = rep(1:2, each = 4),
    second_id = rep(rep(letters[1:2], 2), each = 2),
    variable = as.character(c(2, 1, NA, 2, 3, 1, 3, NA))
  )
  
  # A tibble: 8 x 3
    first_id second_id variable
       &lt;int&gt; &lt;chr&gt;     &lt;chr&gt;   
  1        1 a         2       
  2        1 a         1       
  3        1 b         NA      
  4        1 b         2       
  5        2 a         3       
  6        2 a         1       
  7        2 b         3       
  8        2 b         NA    
  </code></pre>
  
  <p>The value may have a different meaning according to: </p>
  
  <ul>
  <li><p>the <code>first_id</code> column, i.e 1 may be <code>Yes</code> if <code>first_id</code> is equal to 1 and it can be <code>maybe</code> if <code>first_id</code> is equal to to 2.</p></li>
  <li><p>the <code>second_id</code> column.</p></li>
  </ul>
  
  <p>To visualize more easily, think that this dataframe corresponds to survey data where <code>first_id</code> refers to different rounds and <code>second_id</code> to different countries.</p>
  
  <p>Therefore, I would like to replace these values according to their <code>first_id</code> and <code>second_id</code>. I would like to replace the unique values of the column <code>variable</code> with a vector because I have a lot of different values and I think it's a better option than doing:</p>
  
  <pre><code>my_data$variable[(my_data$first_id == 1 &amp; my_data$second_id == "a" &amp; my_data$variable == "1")] &lt;- "Something"
  my_data$variable[(my_data$first_id == 1 &amp; my_data$second_id == "a" &amp; my_data$variable == "2")] &lt;- "Something else"
  </code></pre>
  
  <p>etc.</p>
  
  <p>I tried to do something like:</p>
  
  <pre><code>sort(unique(my_data$variable[(my_data$first_id == 1 &amp; my_data$second_id == "a")])) &lt;- c("Something", "Something else")
  </code></pre>
  
  <p>but I have the error:</p>
  
  <blockquote>
    <p>Error in sort(unique(my_data$variable[(my_data$first_id == 1 &amp; my_data$second_id ==  : 
      impossible de trouver la fonction "sort&lt;-"</p>
  </blockquote>
  
  <p>How can I replace unique values of a subsetted dataframe with a vector?</p>
  
  <p>Expected output:</p>
  
  <pre><code># A tibble: 8 x 3
    first_id second_id variable      
       &lt;int&gt; &lt;chr&gt;     &lt;chr&gt;         
  1        1 a         Something else
  2        1 a         Something     
  3        1 b         NA            
  4        1 b         2             
  5        2 a         3             
  6        2 a         1             
  7        2 b         3             
  8        2 b         NA   
  </code></pre>