title: set na all values that starts with certain string in dplyr environment is.na(), na_if(), startsWith(), regex
body: <p>I have data frame of several character and numerical variables. I want to set all values starting with <code>0/n(</code> to <code>NA</code> . Theses values may be spread over several columns.</p>
  <p>Example:</p>
  <pre><code>string &lt;- c(&quot;asff&quot;, &quot;1\n(&quot;, '0asfd', '0\n(asdf)')
  num &lt;- c(0,1,2,3)
  df &lt;- data.frame(string, num)
  ##
  df
       string num
  1      asff   0
  2      1\n(   1
  3     0asfd   2
  4 0\n(asdf)   3
  </code></pre>
  <p>Desired output:</p>
  <pre><code>     string num
  1      asff   NA
  2      1\n(   1
  3        NA   2
  4        NA   3
  </code></pre>
  <p>The numerical variables are quickly set to NA by:</p>
  <pre><code>df%&gt;%na_if(., 0)
  </code></pre>
  <p>But the character string doesn't seem to work as easy with <code>na_if()</code>, as <code>na_if()</code> does not seem to work with regex, does it? I tried things like:
  <code>na_if(., &quot;^0.&quot;)</code>
  <code>na_if(., &quot;0.&quot;)</code>
  <code>na_if(., startsWith(&quot;0&quot;))</code>, but ERROR ...</p>
  <p>Maybe a conditional<code>dplyr::mutate(.=ifelse())</code> with a regex, but then I have these line breaks <code>&quot;\n)&quot;</code>, which or not captured by <code>&quot;.&quot;</code> in a regex. Or something with  <code>mutate(x = str_replace_all())</code>.</p>
  <p>I can do it column by column (<code>df%&gt;%mutate(x = ifelse(startsWith(x, &quot;0&quot;), NA,x )))</code>), but that's too much hard coding. I can not apply it to all columns with <code> mutate(across(colnames(), ~ifelse(startsWith(., &quot;0&quot;), NA, .)))</code> as the numerical columns trigger an error.</p>