R/make.R

Defines functions make_percent make_numeric

Documented in make_numeric make_percent

# nolint start

#' Clean up a character vector to make it numeric
#'
#' Remove commas & whitespace, primarily
#'
#' @param x character vector to process
#' @return numeric vector
#' @export
make_numeric <- function(x) { as.numeric(gsub(",", "", trimws(x))) }

#' Clean up a character vector to make it a percent
#'
#' Remove "%" primarily, convert to numeric & divide by 100
#'
#' @param x character vector to process
#' @return numeric vector
#' @export
make_percent <- function(x) { as.numeric(gsub("%", "", trimws(x))) / 100 }

# nolint end
hrbrmstr/hrbrmisc documentation built on May 1, 2023, 7:39 a.m.