title: How to rename raster with same names and order of the training data in model in R
body: <p>I am new to machine learning and not very familiar with lists. I need to raster stack layers (Ras) to be in the <strong>same order</strong> as the training data using in the model (xgb_train_1). The names are in a component called finalModel called feature names. I have tried to reference this list in a list in several ways:</p>
  <p>so: xgb_train_1 -&gt; finalModel -&gt; feature_names</p>
  <pre><code>Ras1 &lt;- Ras[xgb_train_1$finalModel['feature_names']]
  Ras1 &lt;- Ras[xgb_train_1$finalModel[feature_names]]
  Ras1 &lt;- Ras[xgb_train_1[finalModel[feature_names]]]
  </code></pre>
  <p><strong>None work</strong> and I receive the error &quot;NULL&quot; when I call Ras1</p>
  <pre><code>str(xgb_train_1$finalModel)
  
  List of 13
   $ handle       :Class 'xgb.Booster.handle' &lt;externalptr&gt; 
   $ raw          : raw [1:300765128] 7b 22 43 6f ...
   $ niter        : num 10000
   $ call         : language xgboost::xgb.train(params = list(eta = param$eta, max_depth = param$max_depth,      gamma = param$gamma, colsampl| __truncated__ ...
   $ params       :List of 8
    ..$ eta                : num 0.01
    ..$ max_depth          : num 20
    ..$ gamma              : num 1
    ..$ colsample_bytree   : num 1
    ..$ min_child_weight   : num 3
    ..$ subsample          : num 1
    ..$ objective          : chr &quot;reg:squarederror&quot;
    ..$ validate_parameters: logi TRUE
   $ callbacks    :List of 1
    ..$ cb.print.evaluation:function (env = parent.frame())  
    .. ..- attr(*, &quot;call&quot;)= language cb.print.evaluation(period = print_every_n)
    .. ..- attr(*, &quot;name&quot;)= chr &quot;cb.print.evaluation&quot;
   $ feature_names: chr [1:20] &quot;Age&quot; &quot;Drainage&quot; &quot;HSG&quot; &quot;LU2005&quot; ...
   $ nfeatures    : int 20
   $ xNames       : chr [1:20] &quot;Age&quot; &quot;Drainage&quot; &quot;HSG&quot; &quot;LU2005&quot; ...
   $ problemType  : chr &quot;Regression&quot;
   $ tuneValue    :'data.frame':  1 obs. of  7 variables:
    ..$ nrounds         : num 10000
    ..$ max_depth       : num 20
    ..$ eta             : num 0.01
    ..$ gamma           : num 1
    ..$ colsample_bytree: num 1
    ..$ min_child_weight: num 3
    ..$ subsample       : num 1
   $ obsLevels    : logi NA
   $ param        : list()
   - attr(*, &quot;class&quot;)= chr &quot;xgb.Booster&quot;
  </code></pre>