# pickSizeBest() for recursive feature elimination [closed]

I'm struggling providing my recursive feature elimination (RFE) function with valid arguments. This question is technically pretty specific so I hope I've hit the right Forum to ask it.

I want to eliminate features using XGBoost model. According to caret documentation for RFE (http://topepo.github.io/caret/rfe.html#rfe), XGBoost is not provided by default so I need to create custom ctrl$functions (control function for rfe()), which looks something like this:  rfRFE <- list(summary = defaultSummary, fit = xgbFit # defined elsewhere using xgboost package pred = function(object, x) predict(object, x), rank = function(object, x, y) { vimp <- varImp(object) vimp <- vimp[order(vimp$Overall,decreasing = TRUE),,drop = FALSE]
vimp\$var <- rownames(vimp)
vimp
},
**selectSize = pickSizeBest,**
selectVar = pickVars
)


pickSizeBest() causes me problems!

When I call the function like this:

    example <- data.frame(RMSE = c(1.2, 1.1, 1.05, 1.01, 1.01, 1.03, 1.00),
Variables = 1:7)
cat("Finding the row with the absolute smallest RMSE")
smallest <- pickSizeBest(example, metric = "RMSE", maximize = FALSE)


it works fine (which perfectly makes sense), but what I want is to provide my train data and when try to do so (for example, train[2:127]), I get this error, for which I haven't found a solution:

    Error in [.data.frame(x, , metric) : undefined columns selected


I know that the syntax for train is fine so I have no idea what should I provide to satisfy this function's argument.

## closed as off-topic by gung♦Aug 27 '18 at 18:53

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – gung
If this question can be reworded to fit the rules in the help center, please edit the question.

If you look at ?pickSizeBest you should see:
    - x -> a matrix or data frame with the performance metric of interest