title: Mutate and replace few columns at once
body: <p>I have df such as:</p>
  
  <pre><code>  outc  task  prevt 
    &lt;fct&gt; &lt;fct&gt; &lt;fct&gt; 
  1 los   fre   rep   
  2 los   fre   swi   
  3 los   ins   rep   
  4 los   ins   swi   
  5 win   fre   rep   
  6 win   fre   swi   
  7 win   ins   rep   
  8 win   ins   swi   
  </code></pre>
  
  <p>I want to replace values in column task and prevt, depending on the value in each of these columns. For example, if task is 'fre' AND prevt is 'rep', then task should be changed to 'ins' and prev should be changed to 'swi'. The key thing is that I need to change it all at once, as if I do it one after another, then the result would be different from what I want. So it seemed like easy task to do with mutate and replace:</p>
  
  <pre><code>df %&gt;% 
    mutate(task = replace(task, task == 'fre' &amp; prevt == 'rep', 'ins'),
           prevt = replace(prevt, task == 'fre' &amp; prevt == 'rep', 'swi')) 
  </code></pre>
  
  <p>But for some reason, only the first part of mutate works in this case, i.e. task column is changed, but prevt column is not. </p>
  
  <pre><code>  outc  task  prevt
    &lt;fct&gt; &lt;fct&gt; &lt;fct&gt;
  1 los   ins   rep  
  2 los   fre   swi  
  3 los   ins   rep  
  4 los   ins   swi  
  5 win   ins   rep  
  6 win   fre   swi  
  7 win   ins   rep  
  8 win   ins   swi  
  </code></pre>
  
  <p>If I change second part to some non-conditional value (e.g. prevt = '1'), then it works. </p>
  
  <pre><code>df %&gt;% 
    mutate(task = replace(task, which(task == 'fre' &amp; prevt == 'rep'), 'ins'),
           prevt = '1')
  
    outc  task  prevt
    &lt;fct&gt; &lt;fct&gt; &lt;chr&gt;
  1 los   ins   1    
  2 los   fre   1    
  3 los   ins   1    
  4 los   ins   1    
  5 win   ins   1    
  6 win   fre   1    
  7 win   ins   1    
  8 win   ins   1   
  </code></pre>
  
  <p>So for some reason two replace does not work within mutate. Can you please help me what could I do in this case?</p>