Reputation: 10350
I want to predict a randomForest
object to a huge RasterStack
.
The randomForest
object was trained with a dataframe
with vairables named like "05_absor_1", "05_absor_2" ...
The RasterStack
has 189 layers, which are names like "X05_absor_1", "X05_absor_2" ...
I tried to change the names of the layers of the RasterStack
, but, as it occurs, they cannot be named beginning with a number.
Is there any possibility to adapt these two data sets to each other by renaming the variable names of the RandomForest
object?
Upvotes: 2
Views: 1297
Reputation: 162
Better late then never
You can't rename the variables in the randomForest object, but you can extract the Raster stack. Then you can change the colnames, predict the model on the exracted dataframe. At the end you can overwrite the raster cell values of one rasterlayer in the stack with the values of the predicted data frame. This will present your prediciton on the raster stack.
Look at this post, facing a similar issue with spaces in the model variable names:
https://stackoverflow.com/a/66301739/13440906
Upvotes: 1