I have spatraster stack, how can I update the max value for each layer with a value from a seperate dataframe? The names of rasters match the column names in the dataframe.
I'm very new to R and terra, but so far I have tried writing a for loop but my computer crashes.
Here is my code
for (i in 1:nlyr(rast)) {
layer_values <- winter_rastI[[i]]
layer_values[layer_values == 1] <- maxvalues[i]
rast[[i]] <- layer_values
}
Example data
Get the max values
Use a loop
or lapply