#' Calculate Statsitics for all DRG Codes
#'
#' @param df
#' @param statistic
#'
#' @return data frame
#' @export
#'
#' @import dplyr
#' @importFrom purrr map_df
#'
#' @examples DRG_statistic(drg_data, 'mean')
DRG_statistic <- function(df, ## dataframe
statistic ##statistic to be calculated
){
##use the spread function to turn the data into wide format
drg.data.wide <- df %>%
select(DRG.Definition,
Provider.Id,
Provider.State,
Average.Medicare.Payments) %>%
spread(DRG.Definition, Average.Medicare.Payments)
##calculate the statsitic of interest over each of the columns of the dataframe
ap.map <- drg.data.wide %>%
select(-Provider.Id,
-Provider.State) %>%
map_df(get(statistic), na.rm = TRUE)
##return the results
return(ap.map)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.