0

I have a list of a spatial dataset and a stack of rasters. The sf represent fires from 1985 to 2017 and the stack of rasters represent the climate conditions from 1985 to 2017. I want to extract the raster values for each pixel in the fire polygons using the exact_extract function in R. The function has the argument include_cols which is an optional character vector of column names in sf to be added to the data frame. Also, it has the argument append_cols that do the same when the fun is not NULL. However, when I try to apply the function I get the following error:

Error in `[.data.frame`(x, i, j, drop = drop) : 
  undefined columns selected 

Here is my code:

waterclimPre_extract<- mapply(x= waterclimPre_maps, y = polys_maps, FUN= function(x,y)
  exact_extract(x, y, include_xy = T, include_cell=T, include_cols = c("year", "fireClas")))

and also:

waterclimPre_stat <- mapply(x= waterclimPre_maps, y = polys_maps, FUN= function(x,y)
    exact_extract(x, y, fun = c("mean", "min", "max", "median", "variance"), append_cols = c("year", "fireClas")))
1
  • 2
    We don't have your data so we cant run your code and reproduce this. Can you make a simple example that shows the problem? Can you show us summaries of the input data? Can you take the mapply out of the equation and show the problem with just a call to exact_extract? Can you show which packages you used?
    – Spacedman
    Commented Apr 2, 2021 at 9:21

1 Answer 1

0

The source of the error was that not all SF in the list had the same name in the columns. One, in particular, had "Year" instead of "year".

1
  • It would be great if you would mark your answer as the solution, this way it is clear to everyone at first sight.
    – Pieter
    Commented Sep 7 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.