I have a data frame with observations, each of them has, among others, coordinates where the observation was taken, and the year where it was taken.
I want to add a column with the temperature at these coordinates and year, and I have a raster file with the mean temperature of the region at each year, therefore 40 rasters, per 40 years.
I am quite noob at working with R and GIS. For now, I would group the observations per year, and then extract the temperature per each coordinates of each year. But since I have over 40 years, I was wandering if there is a faster way to do this. Here a bit of code to have a better idea of the problem, to create this data frame:
Species Year Longitud Latitude
1 S.pilchardus 2014 8 52
2 T. silvestris 2010 8 54
3 C. monogyna 2014 9 58
4 C. monogyna 2010 8 55
5 T. silvestris 2015 4 55
6 M.novaezelandiae 2014 5 51
7 T. silvestris 2011 5 52
8 S.pilchardus 2015 3 50
9 C. monogyna 2014 1 60
10 M.novaezelandiae 2013 4 58
species = c("C. monogyna", "T. silvestris",
"M.novaezelandiae", "S.pilchardus")
database = data.frame(Species = sample(species, 10, replace = T),
Year = sample(2010:2015,10, replace = T),
Longitud = sample(1:10, 10, replace = T),
Latitude = sample(50:60, 10, replace = T))
raster = stack(temperature_2010_2015)
Assuming that raster is a stack group of 6 rasters, one per each year from 2010 to 2015, how could I add a column to the "database" object, that contains the value of temperature for the "Longitude, Latitude" coordinates in the year of the row?