R/variable_summmaries.r

Defines functions variable_summaries

Documented in variable_summaries

#' Compute variable summaries.
#'
#' @param dataframe data.frame. A dataset to compute summaries from. The
#' @return a list with "missing_percentages", "means", and "standard_deviations"
#'    for each numeric variable.
#' @export
variable_summaries <- function(dataframe) {
  numeric_cols <- vapply(dataframe, is.numeric, logical(1))
  list(
     missing_percentages = vapply(dataframe, function(x) mean(is.na(x)), numeric(1))
   , means = vapply(dataframe[, numeric_cols], function(x) mean(x, na.rm = TRUE), numeric(1))
   , standard_deviations = vapply(dataframe[, numeric_cols], function(x) sd(x, na.rm = TRUE), numeric(1))
  )
}
robertzk/statsUtils documentation built on July 26, 2019, 5:39 p.m.