title: Using variable names for column in if else R
body: <p>This is my data set</p>
  <pre><code>aa &lt;- c(1,NA,NA,NA,NA)
  bb &lt;- c(2,1,NA,NA,NA)
  cc &lt;- c(5,NA,NA,1,2)
  df &lt;- data.frame(group,aa,bb,cc)
  </code></pre>
  <pre><code>group aa bb cc
  1     1  1  2  5
  2     1 NA  1 NA
  3     2 NA NA NA
  4     2 NA NA  1
  5     2 NA NA  2
  </code></pre>
  <p>where,
  I have to give variable names to the columns</p>
  <pre><code>category&lt;-&quot;group&quot;
  A&lt;-&quot;aa&quot;
  B&lt;-&quot;bb&quot;
  C&lt;-&quot;cc&quot;
  </code></pre>
  <p>I want to replace the NA values by 0 in column &quot;aa&quot;, where, group !=1, but I have to use the variables <strong>A</strong> and <strong>category</strong> instead</p>
  <p>The output would look like</p>
  <pre><code>  group aa bb cc
  1     1  1  2  5
  2     1 NA  1 NA
  3     2  0 NA NA
  4     2  0 NA  1
  5     2  0 NA  2
  </code></pre>
  <p>I have tried:</p>
  <pre><code>library(dplyr)
  library(tidyverse)
  
  df %&gt;% 
    mutate_at(.vars = A, .funs = funs(if_else(category!= 1 &amp; is.na(.), 0, .)))
  </code></pre>
  <p>,
  it is not working</p>
  <p>Note:
  The above output was obtained using</p>
  <pre><code>df %&gt;% 
    mutate_at(.vars = A, .funs = funs(if_else(group != 1 &amp; is.na(.), 0, .)))
  </code></pre>
  <p>(I have to use
  <strong>&quot;category&quot;</strong> instead of <strong>&quot;group&quot;</strong>)</p>