#' See which players lead a stat
#'
#' Extract common mob names from a list of mob stats. Uses \code{strings.entities} for
#' substitutions of some mob names.
#' @keywords playerstats
#' @param playerstats The player stat from which the leading players should be calculated, like \code{entities},
#' \code{items} etc.
#' @param dataset Dataset of summary stats like \code{mobStats} or \code{itemStats}
#' @param trailing If \code{TRUE}, the trailing players are returned instead of the leading players
#' @return Vector names
#' @import stringr
#' @export
#' @note Required to produce \code{mobStats}, see \link[wurstmineR]{getMobStats}
#' @examples
#' \dontrun{
#' getLeadingPlayers(mobStats, entities)
#' }
getLeadingPlayers <- function(dataset, playerstats = NULL, trailing = FALSE){
maxPlayers <- lapply(dataset$stat, function(stat){
if (!trailing){
players <- playerstats[playerstats[[stat]] == max(playerstats[[stat]]), "player"]
} else {
players <- playerstats[playerstats[[stat]] == min(playerstats[[stat]]), "player"]
}
players <- stringr::str_join(players, collapse=" and ")
})
maxPlayers <- unlist(maxPlayers)
return(maxPlayers)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.