title: How to avoid the memory limit in R
body: <p>I'm trying to replace values in a matrix, specifically "t"->1 and "f"->0, but I keep getting the error messages: </p>
  
  <pre><code>Error: cannot allocate vector of size 2.0 Mb
  ...    
  Reached total allocation of 16345Mb: see help(memory.size)
  </code></pre>
  
  <p>I'm using a Win7 computer with 16GB of memory on the 64-bit version of R in RStudio.</p>
  
  <p>what i'm currently running is </p>
  
  <pre><code>a &lt;- matrix( dataset, nrow=nrow(dataset), ncol=ncol(dataset), byrow=TRUE)
  memory.size()
  a[a=="t"] &lt;- 1
  </code></pre>
  
  <p>where dataset is a (about) 525000x300 size data frame. the <code>memory.size()</code> line gives me less than 4GB used, and <code>memory.limit()</code> is 16GB. Why is it that the replace line would require so much memory to execute? Is there any way to do the replace without hitting the memory limit (and are there any good tips on avoiding it in general), and if so, is it going to cost me a lot of time to run it? I'm still pretty new to R so I don't know if it makes a difference depending on the data class I use and how R allocates memory...</p>