title: How to better write code for extracting raster data in R. Maybe a loop?
body: <p>I am still getting my feet wet with R. I have an idea to migrate some ArcView functions into R with the following scripts. I would love to be able to have my df help fill in. Would I go about this by writing long pipes for each of the metrics I am concerned with at the bottom (range, avg1, avg2) then running it through a loop? There isn't a point in making my dumby data since I have no dumby raster data available.</p>
  <pre><code>library(rgdal)
  library(sp)
  library(raster)
  
  df &lt;- data.frame(location = paste('location', 1:4), 
               latitude = c(35.123+(1:4)), longitude = c(-120.123+(1:4)))
  </code></pre>
  <p>#steps create shapefiles</p>
  <p>#load raster data</p>
  <pre><code>a &lt;- raster(x= 'data/raster/a.tif')#datum=NAD83
  b &lt;- raster(x= 'data/raster/b.tif')#datum=NAD83
  c &lt;- raster(x= 'data/raster/c.tif')#datum=NAD83
  </code></pre>
  <p>#extract from</p>
  <pre><code>location1_ws_a &lt;- raster::extract(a,location, df= TRUE)
  location1_ws_b &lt;- raster::extract(b,location, df= TRUE)
  location1_ws_c &lt;- raster::extract(c,location, df= TRUE)
  
  range &lt;- max(location1_ws_b)-min(location1_ws_b)
  avg1 &lt;- mean(location1$a)
  avg2 &lt;- mean(location1$c)
  
  output &lt;- data.frame(location,
                   range,
                   avg1,
                   avg2)
  </code></pre>
  <p>In the end I would like a table that has columns name c(location, range, avg1, avg2) with rows location1, location2, location3 and their results
  Many Thanks!!!</p>