Loop through each row in a data frame, extract values from raster and write csv files
<p>I have a data frame with a <code>Name</code>, <code>longitude</code> and <code>latitude</code> columns. I want a function that goes trough each row, extract the values from a raster stack and write csv files based on the <code>Name</code> column.</p>

<pre><code>Name    Lon     Lat
Name1   11.11   47.87
Name2   150.1   -40.4
Name3   -50.2   -3.5
Name4   -100.3  49.8

library(raster)
s &lt;- stack(replicate(5, {raster(matrix(runif(2160*4320), 2160), 
         xmn=-180, xmx=180, ymn=-90, ymx=90)}))

I can do that one by one:

location &lt;- data.frame(11.11, 47.87)
ex &lt;- extract(s, location)
write.csv(ex, "Name1.csv")
</code></pre>