R/reshape.R

#' Melt wide-formatted returns
#'
#' A wrapper for [data.table::melt()] in the common case where candidates are in
#' columns and cells give votes.
#' @inheritParams write_precincts
#' @inheritParams data.table::melt
#' @export
melt_votes = function(.data, ..., na.rm = TRUE, value.name = 'votes', variable.name = 'candidate',
  variable.factor = FALSE, value.factor = FALSE) {
  if (!is.data.table(.data)) setDT(.data)
  melt(.data, ..., na.rm = na.rm, value.name = value.name, variable.name =
    variable.name, variable.factor = variable.factor, value.factor = FALSE)
}
MEDSL/medslcleaner documentation built on May 31, 2019, 7:39 a.m.