title: Mutate across with ifelse and is.na
body: <p>I have data in the format outlined below, where all of the variables I need to work with are either <code>NA</code> or the name of the variable, and I need to change the NAs to 0 and the strings to 1. I'm trying to use <code>dplyr::across()</code> and <code>ifelse()</code>, but what gets returned is all 1s. The only solution I have right now that works is mutating each variable individually.</p>
  <p>How would I change all <code>NA</code>s to 0 and all strings to 1 across multiple variables at once?</p>
  
  <pre class="lang-r prettyprint-override"><code>library(dplyr)
  color_names &lt;- c(&quot;black&quot;, &quot;grey&quot;, &quot;white&quot;, &quot;purple&quot;)
  
  my_colors &lt;- tribble(
    ~black, ~grey, ~white,  ~purple,
    NA,     &quot;grey&quot;, NA,     &quot;purple&quot;,
    NA,     NA,     &quot;white&quot;, NA,
    &quot;black&quot;,NA,     NA,      NA,
    NA,     &quot;grey&quot;,  NA,     NA
  )
  
  my_colors %&gt;%
    mutate(across(all_of(color_names), ~ifelse(is.na(cur_column()), 0, 1)))
  #&gt; # A tibble: 4 x 4
  #&gt;   black  grey white purple
  #&gt;   &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;  &lt;dbl&gt;
  #&gt; 1     1     1     1      1
  #&gt; 2     1     1     1      1
  #&gt; 3     1     1     1      1
  #&gt; 4     1     1     1      1
  </code></pre>
  <p><sup>Created on 2021-01-13 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>