title: Eloquently change many raster cell values in R
body: <p>I have a Landfire Existing Vegetation dataset (<a href="http://www.landfire.gov/" rel="nofollow">http://www.landfire.gov/</a>), which I have projected and cropped to my study site.  The raster has ~12,000,000 cells.  The cell values represent a particular vegetation type, and the values range from 16:2200.  All of those values are not represented in my study area (i.e. values jump from 20 to 1087).</p>
  
  <p>As many of the pixels' values can be lumped together into one classification for my purposes (e.g. different shrub communities into one class), I wanted to reset the values of the raster to simpler values (1:11).  This will facilitate easy extraction of data from other rasters by vegetation type and ease of plotting the classification map.  I have a working code, but it requires a ton of typing to change all 61 of the values I need to change.  Here's what I did:</p>
  
  <pre><code>#===============================
  ############Example#############
  #===============================
  
  library(raster)
  r &lt;- raster(nrows=30, ncols=10, xmn=0, xmx=10)
  r[] &lt;- rep(10:19, 30)
  
  r.omance &lt;- function(x){
              x[x==10] &lt;- 1; x[x==11] &lt;- 1; x[x==12] &lt;- 1
              x[x==13] &lt;- 1; x[x==14] &lt;- 1; x[x==15] &lt;- 1
  
              x[x==16] &lt;- 2; x[x==17] &lt;- 2; x[x==18] &lt;- 2
              x[x==19] &lt;- 2
              return(x)}
  
  reclass &lt;- calc(r, fun = r.omance) 
  </code></pre>
  
  <p>Does anyone know of an easier way to go about this?  You can imagine the typing to change 61 values, especially since x[x==16:20] &lt;- 1 was producing an error, so every value had to be typed out separately.  As I said, my code works.  But I just want to become a better R coder.</p>
  
  <p>Thanks.</p>