title: tidyverse and dplyr: Conditional replacement of values in a column based on other column
body: <p>I want to mutate a column <code>A4</code> by <code>A3</code> but reducing value of <code>A3</code> by 1 if <code>Total == 63</code>. What am I doing wrong here?</p>
  <pre><code>tb1 %&gt;% 
    mutate(A4 = replace(A3, Total == 63, A3-1))
  </code></pre>
  <p>The complete code with data is here</p>
  <pre><code>library(tidyverse)
  
  tb1 &lt;-
  structure(
    list(
      A1 = c(16, 11, 16, 18, 20, 19, 16, 18, 20, 15, 
            17, 19, 19, 19, 16, 19, 16, 15, 19, 19, 16, 18, 18, 19, 19, 18, 
            20, 18, 19, 19, 19, 19, 17, 19, 17, 16, 18, 19, 16, 18, 17, 19, 
            19, 20, 17, 16, 18, 16, 15, 19, 19, 17, 20, 18, 16, 19, 19, 15, 
            17, 17, 19, 19, 16, 17, 18, 19, 17, 19, 17, 15, 19, 16, 17
            )
          , A2 = c(8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
                8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
                8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 
                8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
                )
        , A3 = c(33, 34, 38, 36, 36, 34, 41, 36, 40, 38, 38, 41, 38, 34, 33, 36, 
              41, 40, 41, 38, 41, 33, 40, 38, 40, 38, 41, 41, 40, 41, 40, 
              38, 34, 40, 36, 41, 40, 40, 33, 38, 36, 41, 40, 40, 28, 41, 
              40, 41, 33, 41, 36, 36, 40, 34, 41, 41, 38, 38, 41, 38, 41, 
              41, 36, 40, 38, 38, 40, 41, 38, 22, 36, 34, 38
              )
          , Total = c(57, 53, 62, 62, 64, 61, 65, 62, 68, 61, 63, 68, 65, 61, 57, 63, 
          65, 63, 68, 65, 65, 59, 66, 65, 67, 64, 69, 67, 67, 68, 67, 
          65, 59, 67, 61, 65, 66, 67, 57, 64, 61, 68, 67, 68, 53, 65, 
          66, 65, 56, 68, 63, 61, 68, 60, 65, 68, 65, 61, 66, 63, 68, 
          68, 60, 65, 64, 65, 65, 68, 63, 45, 63, 58, 63
          )
      )
    , class = &quot;data.frame&quot;
    , row.names = c(NA, -73L)
    )
  
  tb1 %&gt;% 
    filter(Total == 63)
  #&gt;   A1 A2 A3 Total
  #&gt; 1 17  8 38    63
  #&gt; 2 19  8 36    63
  #&gt; 3 15  8 40    63
  #&gt; 4 19  8 36    63
  #&gt; 5 17  8 38    63
  #&gt; 6 17  8 38    63
  #&gt; 7 19  8 36    63
  #&gt; 8 17  8 38    63
  
  tb2 &lt;- 
    tb1 %&gt;% 
    mutate(A4 = replace(A3, Total == 63, A3-1)) %&gt;% 
    mutate(Total = A1 + A2 + A3)
  #&gt; Warning: Problem with `mutate()` input `A4`.
  #&gt; x number of items to replace is not a multiple of replacement length
  #&gt; ℹ Input `A4` is `replace(A3, Total == 63, A3 - 1)`.
  
  tb2 %&gt;% 
    filter(Total == 62)
  #&gt;   A1 A2 A3 Total
  #&gt; 1 16  8 38    62
  #&gt; 2 18  8 36    62
  #&gt; 3 18  8 36    62
  </code></pre>