title: Finding a value for a variable according to different elevations
body: <p>I have a DEM raster file of a specific region</p>
  <pre><code>DEMRASTER
  
  class      : RasterLayer 
  dimensions : 47, 89, 4183  (nrow, ncol, ncell)
  resolution : 0.5, 0.5  (x, y)
  extent     : 60.75, 105.25, 15.75, 39.25  (xmin, xmax, ymin, ymax)
  crs        : NA 
  source     : memory
  names      : newlowelevation1 
  values     : 1, 6136.012  (min, max)
  </code></pre>
  <p>I have another raster file of variable &quot;GPP&quot;:</p>
  <pre><code>GPPRASTER
  class      : RasterLayer 
  dimensions : 47, 89, 4183  (nrow, ncol, ncell)
  resolution : 0.5, 0.5  (x, y)
  extent     : 60.75, 105.25, 15.75, 39.25  (xmin, xmax, ymin, ymax)
  crs        : NA 
  source     : memory
  names      : layer 
  values     : -0.333333, 0  (min, max)
  </code></pre>
  <p>How can I find the values of the GPP raster according to elevation? For instance, if I want to find a mean value of GPP for elevation from 0-2000m or 5500 to 6136m? What will be the basic code for this?</p>
  <p>I have tried removing pixels based on the elevation that I did not want from the DEM raster file, but it is a method that takes too long. I am sure that there is a code for this, but can't put my hand on it as I am a new beginner at R myself. Thanks in advance!</p>