4

I have a dataframe containing the best predictors by their contribution to a model:

bestpredictors
           var contrib
2  Pfallwinter  8.1141
15      Tofall 58.0000
23          ai  5.3573
26     radmean  7.9753
27   radseason  0.9027 

Every variable name is also a raster object. So, how can I make a raster stack with those variables? Like this:

predictors<-stack(Pfallwinter,Tofall,ai,radmean,radseason)

I have tried to extracting the string character and using the do.call and eval functions but seems that isn't the correct way, because they can't call the object already saved.

1 Answer 1

4

You can use mget() to search for objects given a character vector.

predictors<-stack(mget(unique(as.character(bestpredictors$var))))
0

Your Answer

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

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