I am trying to get some elevations for bird locations I have in NZ. I thought I might use the code provided as an answer to a similar question (Extracting elevation from website for lat/lon points in Australia, using R), unfortunately I get errors when using the extract function in the raster package, even though the code is almost identical.
library(raster)
m <- data.frame(lon = c(172.639847, 173.283966), lat = c(-43.525650, -41.270634))
x <- getData('alt', country = "NZL")
cbind(m, alt = extract(x, m))
plot(x)
points(m)
ERROR:
cbind(m, alt = extract(x, m))
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘extract’ for signature ‘"list", "data.frame"’
Can anyone tell me what is going wrong? I have been searching for hours but cannot find a solution.
Thanks, Sam