#' Runs a function on the values of a melted data frame.
#' Used for preforming median, mean, sd, and sum without a ton of ugly scripting.
#' @param fetch_group. The result of a fetch_var()
#' @param fn. The name of the function.
#'
#' e.g., the median age would be \code{fn_on_df(fetch('age'), median)}
#' @export
fn_on_df <- function(fetch_group, fn, na.rm = NULL, ...) {
if (c(fn) %in% c(mean, median, sd) && is.null(na.rm))
fn(as.numeric(fetch_group), na.rm = TRUE, ...)
else
fn(as.numeric(fetch_group), ...)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.