R/function2.R

Defines functions oldest_player

Documented in oldest_player

#' Oldest NBA Player Function
#'
#' This function allows you to see which player was the oldest in a given year
#' @param year Who was the oldest player this year?
#' @keywords age
#' @export
#' @examples
#' oldest_player()

oldest_player <- function(year) {
  year_nba <- subset(nba, nba$Year == year)
  max_age <- year_nba %>%
    summarise(max(Age))
  oldest_player <- year_nba %>%
    filter(Age %in% max_age) %>%
    group_by(Player) %>%
    arrange(Player) #ordered alphabetical if there are multiple people

  print(paste0("Oldest Player in ", year, ": ",oldest_player$Player[1]))

}
dustintdn/mdshw5R documentation built on May 6, 2022, 12:25 a.m.