title: Replace Value in column based on another column With R
body: <p>I'm trying to replace the value of a column based on the data in a different column, but it's not working.  Here's some example data.</p>
  <pre><code>df &lt;- data.frame(Col1 = 1:10,
                   Col2 = c(&quot;a&quot;, &quot;a&quot;, &quot;a&quot;, &quot;b&quot;, &quot;b&quot;, &quot;c&quot;, &quot;c&quot;, &quot;d&quot;, &quot;d&quot;, &quot;d&quot;),
                   Col3 = c(&quot;11%&quot;, &quot;12%&quot;, &quot;13%&quot;, &quot;14%&quot;, &quot;15%&quot;, &quot;16%&quot;, &quot;17%&quot;, &quot;18%&quot;, &quot;19%&quot;, &quot;20%&quot;))
  
  </code></pre>
  <p>If the value of Col2 is b, I need to change the value of Col3 to NA or 0 (NA is more accurate, but for what I'm doing, a 0 will also work).  Column 3 is percents, I know I used strings here.</p>
  <p>I tried doing this a few ways, most recently of which is the loop I have listed below.  I'm open to any solution on this though. Is my loop not working because I'm not defining a pattern?</p>
  <pre><code>for(i in df){
    if(df$Col2 == &quot;b&quot;){
      str_replace(df$Col3, replacement = NA)
    }
  }
  
  print(df)
  </code></pre>