title: Replacing occurrences of a number in multiple columns of data frame with another value in R
body: <p><strong>ETA:</strong> the point of the below, by the way, is to not have to iterate through my entire set of column vectors, just in case that was a proposed solution (just do what is known to work once at a time).</p>
  
  <hr>
  
  <p>There's plenty of examples of replacing values in a <em>single</em> vector of a data frame in R with some other value.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/5824173/replace-a-value-in-a-data-frame-based-on-a-conditional-if-statement-in-r">Replace a value in a data frame based on a conditional (<code>if</code>) statement in R</a></li>
  <li><a href="https://stackoverflow.com/questions/11817371/replace-numbers-in-data-frame-column-in-r">replace numbers in data frame column in r [duplicate]</a></li>
  </ul>
  
  <p>And also how to replace all values of <code>NA</code> with something else:</p>
  
  <ul>
  <li><a href="http://r.789695.n4.nabble.com/How-to-replace-all-lt-NA-gt-values-in-a-data-frame-with-another-not-0-value-td2125458.html" rel="noreferrer">How to replace all  values in a data.frame with another ( not 0) value</a></li>
  </ul>
  
  <p>What I'm looking for is analogous to the last question, but basically trying to replace one value with another. I'm having trouble generating a data frame of logical values mapped to my actual data frame for cases where multiple columns meet a criteria, or simply trying to do the actions from the first two questions on more than one column.</p>
  
  <p>An example:</p>
  
  <pre><code>data &lt;- data.frame(name = rep(letters[1:3], each = 3), var1 = rep(1:9), var2 = rep(3:5, each = 3))
  
  data
    name var1 var2
  1    a    1    3
  2    a    2    3
  3    a    3    3
  4    b    4    4
  5    b    5    4
  6    b    6    4
  7    c    7    5
  8    c    8    5
  9    c    9    5
  </code></pre>
  
  <p>And say I want all of the values of <code>4</code> in <code>var1</code> and <code>var2</code> to be <code>10</code>.</p>
  
  <p>I'm sure this is elementary and I'm just not thinking through it properly. I have been trying things like:</p>
  
  <pre><code>data[data[, 2:3] == 4, ]
  </code></pre>
  
  <p>That doesn't work, but if I do the same with <code>data[, 2]</code> instead of <code>data[, 2:3]</code>, things work fine. It seems that logical test (like <code>is.na()</code>) work on multiple rows/columns, but that numerical comparisons aren't playing as nicely?</p>
  
  <p>Thanks for any suggestions!</p>