Error in Rbindlist from a rasterstack and shapefile extraction file

I have multiple rasters files and a grid shapefile.

I load the shapefile:

grid = st_read('/grid.shp')

I load the raster and create a raster stack

`path <- "/VI_tif"`  #folder where I have stored the raster data
    dlist <- dir(path,pattern="VCI.tif")


    for (i in 1:length(dlist)) {                   
      fold <- paste(path,dlist[i],sep="/")         
      fls <- dir(fold,pattern="VCI.tif")              
      flsp <-paste(fold,fls,sep="/")               
      vcistack <- stack(flsp)

Then, I extract the variable from the vcistack according to my grid shapefile:

vci.grid <- exact_extract(vcistack, grid, include_cols=T, include_xy=T, force_df=T)

Finally, I want to transform the list into dataframe:

vci.grid.df <- rbindlist(vci.grid, fill=T, use.names = T)

However, I got the following error message:
Error in rbindlist(vci.grid, fill = T, use.names = T) :
Column 1 of item 1 is length 225 inconsistent with column 9 which is length 50625. Only length-1 columns are recycled

Which I don't understand because when I look at it there are 225 rows, not 50625.

Any ideas how to solve this?

I think I understand what's wrong.

The resolution of the raster stack = 0.03
while the resolution of my grid shapefile = 0.5

So when I extract values, obviously for one grid cell from my shapefile, I will get several values from the raster stack. The number of values I get form the stack differs from one cell to another depending on the location.
Hence, the error when I try to unlist the final file.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.