title: Updating individual values (not rows) in an R data.frame
body: <p>I would like to update values of <code>var3</code> in an R data.frame <code>mydata</code> according to a simple criterion.</p>
  
  <pre><code>   var1  var2  var3
  1  1     4     5
  2  3     58    800
  3  8     232   8 
  </code></pre>
  
  <p>I would think that the following should do:</p>
  
  <pre><code>mydata$var3[mydata$var3 &gt; 500,] &lt;- NA
  </code></pre>
  
  <p>However, this replaces the entire row of every matching record with NA (all cells of the row), instead of just the <code>var3</code> value (cell):</p>
  
  <pre><code>   var1  var2  var3
  1  1     4     5
  2  NA    NA    NA
  3  8     232   8 
  </code></pre>
  
  <p>How can I ensure that just the value for the selected variable is replaced? <code>mydata</code> should then look like</p>
  
  <pre><code>   var1  var2  var3
  1  1     4     5
  2  3     58    NA
  3  8     232   8 
  </code></pre>