How can I extract data from a raster stack based on a list of lat long?
<p>I have a raster stack with 100+ files. And I want to extract the values from each file for particular lat-long locations. This gives me the list of values for one Lat-Long combination.</p>
<pre><code>plist &lt;- list.files(pattern = &quot;\\.tif$&quot;, include.dirs = TRUE)
pstack &lt;- stack(plist)
#levelplot(pstack)

for (i in 1:length(plist))
  t[i]=extract(pstack[[i]], 35,-90)
</code></pre>
<p>How can I do it for thousands of locations when I have the lat-long locations in a separate file/dataframe. There is a location ID that I want to preserve too in the final list:</p>
<pre><code>Lat Long LocID
35 -90   001
35 -95   221
30 -95.4 226
31.5 - 90 776
</code></pre>
<p>My final objective is to have a dataframe of this type:</p>
<pre><code>Lat Long LocID value
35 -90   001   0.5
35 -95   221   1.4
30 -95.4 226   2.5
31.5 - 90 776  4.5
</code></pre>
<p>Though if it is not possible to preserve the LocID, that's fine too.</p>
<p>One of the files: <a href="https://www.dropbox.com/s/ank4uxjbjk3chaz/new_conus.tif?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/ank4uxjbjk3chaz/new_conus.tif?dl=0</a></p>
<hr />
<p>Testing a solution from comments:</p>
<pre><code>latlong&lt;-structure(list(lon = c(-71.506667, -71.506667, -71.506667, -71.215278, 
-71.215278, -71.215278, -71.215278, -71.215278, -71.215278, -71.215278
), lat = c(42.8575, 42.8575, 42.8575, 42.568056, 42.568056, 42.568056, 
42.568056, 42.568056, 42.568056, 42.568056)), .Names = c(&quot;lon&quot;, 
&quot;lat&quot;), row.names = c(NA, 10L), class = &quot;data.frame&quot;)
</code></pre>
<pre><code>ext&lt;-extract(pstack,latlong)
</code></pre>
<p>gives</p>
<blockquote>
<p>Error in UseMethod(&quot;extract_&quot;) :
no applicable method for 'extract_' applied to an object of class &quot;c('RasterStack', 'Raster', 'RasterStackBrick', 'BasicRaster')&quot;</p>
</blockquote>
<p><strong>Update #2:</strong></p>
<p>The error was because it was conflicting with another package. This works:</p>
<pre><code>raster::extract(pstack,latlong)
</code></pre>