R/destring.R

Defines functions destring

Documented in destring

#' Convert character vector to numeric, ignoring irrelevant characters.
#'
#' @param x A vector to be operated on
#' @param keep Characters to keep in, in bracket regular expression form.
#' Typically includes 0-9 as well as the decimal separator (. in the US and , in
#' Europe).
#' @examples
#' destring("24k")
#' destring("5,5")
#'
#' @return vector of type numeric
#' @family vector berekeningen
#' @export destring
destring <- function(x, keep = "0-9.-") {
  return(as.numeric(gsub(paste("[^", keep, "]+", sep = ""), "", x)))
}

Try the vvconverter package in your browser

Any scripts or data that you put into this service are public.

vvconverter documentation built on June 22, 2024, 10:53 a.m.