title: Zonal Statistics R
body: <p>I use the <code>raster</code> package in <code>R</code> und perform an <code>extract</code> on a raster with <code>shapefile</code> that contains several <code>polygons</code> (200). Each polygon has a column where the <code>class</code> of the polygon is specified.
  When I perform the <code>extract</code> I get a <code>dataframe</code> where each value of the raster is "assigned" to a polygon: In which polygon is which pixel located. However, the information that my polygon contains (i.e. what classes the are), are gone. My dataframe after the <code>extract</code> looks something like:</p>
  
  <pre><code>test &lt;- extract(myRaster, myTrainingPolygon, df = TRUE)
  
  ID     band1     band2    band3
  1      0.101     0.827    ...
  ...    ...       ...      ...
  200    0.876     0.821    ...
  </code></pre>
  
  <p>What I need is something like</p>
  
  <pre><code>ID     band1     band2    band3    class
  1      0.101     0.827    ...      class1
  ...    ...       ...      ...      ...
  200    0.876     ...      ...      class3
  </code></pre>
  
  <p>How do I get the information in there - or in the first place - don't lose them when I perform the extract?!</p>