#' Average Medicare Payments Statistics
#'
#' This function is to calculate the \code{statistics} over all of the DRG codes for average medicare payments of data from Centers for Medicare & Medical Services.
#'
#' @param df a dataframe of data from Centers for Medicare & Medical Services. This dataframe must contain DRG codes and average medicare payments data.
#' And the column names of these two variables should be "DRG.Definition" and "Average.Medicare.Payments".
#' @param statistics a character string specifying the type of \code{statistics}, must be one of "mean","median" or "sd".
#'
#' @return a dataframe with DRG codes and \code{statistics} for average medicare payments.
#' @export
#'
#' @importFrom dplyr
#'
#' @examples
#' data(sample_data)
#'
#' average_medicare_payments_statistics(drg_data, 'sd')
#'
#'
average_medicare_payments_statistics <- function(df, statistics){
result <- df %>%
group_by(DRG.Definition) %>%
summarise(mean = mean(Average.Medicare.Payments),
median = median(Average.Medicare.Payments),
sd = sd(Average.Medicare.Payments)) %>%
select(DRG.Definition, all_of(statistics))
return(result)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.