Skip to main content eteppo

Select A Column That Maximizes A Function in R

Published: 2023-08-04
Updated: 2023-08-04
select_maximum <- function(data, evaluation = stats::median, ...) { 
        
  index_max_eval <- data %>%      
    summarise_all(evaluation, ..., .groups = "drop") %>%
    magrittr::extract(1, ) %>%
    as.numeric() %>%
    which.max()
     
  data %>%
    magrittr::extract(index_max_eval)
 
}