R/top_records.R

Defines functions top_records

Documented in top_records

#' @title top_records
#'
#' @param n number of top records from dataset to return
#' @param df data.frame object containing the data of interest
#' @param groupings character vector that is the variable(s) by which to group_by for analysis. This must be input as a string or character vector
#'
#' @import dplyr
#' @export
#'

top_records <- function(n = 5, df, groupings){

  vals <-
    df %>%
    group_by_at(vars(groupings)) %>%
    summarize(
      count = n()
      ) %>%
    arrange(desc(count)) %>%
    head(n)

  return(vals)

}
jtuttle7/LearnFunctions documentation built on May 25, 2019, 6:25 p.m.