Identifies and returns the indices of rows in a data frame where the specified metric reaches the overall maximum within groups defined by one or more columns.
get_best_model_idx(df, metric, group_cols = c("Model", "Engine"))
A numeric vector of row indices in df
corresponding to groups whose maximum metric equals the overall best metric value.
A data frame containing model performance metrics and grouping columns.
A character string specifying the name of the metric column in df
. The metric values are converted to numeric for comparison.
A character vector of column names used for grouping. Defaults to c("Model", "Engine")
.
The function converts the metric values to numeric and creates a combined grouping factor using the specified group_cols
. It then computes the maximum metric value within each group and determines the overall best metric value across the entire data frame. Finally, it returns the indices of rows belonging to groups that achieve this overall maximum.