Hi,
I have a spatial data frame (sf object 280 columns) with 279 variables (columns) plus 1 geometry column,
I am interested in creating 275 rasters (I'd like to skip 4 columns) based on the values stored from column "v1" to "v275 " (the name of my columns are indeed v1,v2,v3 etc )
I have tried to use a for loop but the R session aborts every time I run the loop ..
I have also tried to use the map function from purrr package but I did not succeed ..
I'd really appreciate any advice !!
class(shape_predictions)
[1] "sf" "data.frame"
This is my code
variables<-c(paste("v",1:275, sep = "")) # create a vector containing the variables names to loop over
raster_grid<- rast("data/raster_grid.tif") # import the raster grid used as reference
s <- list()
for (i in variables){
s[[i]] <- rasterize(shape_predictions, raster_grid, shape_predictions[[i]])
}
sr <- stack(s)