Skip to contents

std_num() converts all base classes, as well as int64, factor, Date, and POSIXt vectors to the simplest numeric form possible.

Usage

std_num(x, na = na_patterns, std_chr = TRUE, warn = TRUE, ...)

Arguments

x

A vector to convert to numeric

na

Regex patterns to consider NA. Passed to stringr::str_detect(). Can be a vector of patterns.

std_chr

Whether to standardize a character or factor before conversion

warn

Whether to warn when strings cannot be converted; passed to chr_to_num()

...

Arguments passed on to chr_to_num

std

Whether to standardize the vector before cleaning and converting

convert

Whether to actually convert to numeric

replace

A data.frame of regular expressions and strings to replace them; regular expression should be in a column named pattern, and replacements should be in a column named replacement. Each row is passed to stringr::str_replace().

per_action

How to treat %/percent/per million/etc labels. drop simply removes the labels, divide divides the value by the appropriate denominator, and ignore does nothing.

multiple_decimals

How to handle multiple decimals within a number

donor_host

Which value to use when values for both a donor and a host are given

Value

A numeric vector

Details

character vectors are standardized using std_chr() by default, then converted. factors are treated as character vectors, rather than using the underlying integer representation. double and int64 vectors will be converted to integer if this does not cause overflow or loss of precision. Date is converted to integer, and POSIXt is converted to integer if the range allows, otherwise double.