c_to_n: Extract numeric values from character values

View source: R/c_to_n.R

c_to_nR Documentation

Extract numeric values from character values

Description

Extract numeric values from character values

Usage

c_to_n(x, ...)

## S3 method for class 'character'
c_to_n(
  x,
  ...,
  pattern_numeric = paste0("^[+-]?",
    "(?:[0-9]+|[0-9]+\\.|\\.[0-9]+|[0-9]+\\.[0-9]+)", "(?:[eE][+-]?[0-9]+)?$"),
  verbose = TRUE
)

## S3 method for class 'factor'
c_to_n(x, ...)

## S3 method for class 'numeric'
c_to_n(x, ...)

## S3 method for class 'integer'
c_to_n(x, ...)

## S3 method for class 'logical'
c_to_n(x, ...)

## S3 method for class 'data.frame'
c_to_n(x, ..., verbose = TRUE)

Arguments

x

An object to convert from character to numeric using SDTM or ADaM rules.

...

Passed to other 'c_to_n()' methods

pattern_numeric

A regular expression to detect numeric values.

verbose

Report detailed status of .

Details

The main workhorse function is c_to_n.character, and it will recognize the following numeric types:

  • positive or negative (with optional sign) for all classes

  • integers with an optional decimal point after the number

  • floating point numbers without a number before the decimal point

  • floating point numbers with a number before or after the decimal point

  • scientific notation with any of the prior numeric types as the coefficient and an optional sign before the exponent

Spaces at the beginning and end are removed with 'trimws()'

Value

For vectors, a numeric vector with 'NA' at locations with non-numeric values. For data.frames and similar, the same class of object with numeric versions of columns added.

Methods (by class)

  • c_to_n(character): The main workhorse function of c_to_n

  • c_to_n(factor): For factors.

  • c_to_n(numeric): For numeric vectors.

  • c_to_n(integer): For integer vectors.

  • c_to_n(logical): For logical vectors (only handles all-NA case).

  • c_to_n(data.frame): For data.frames and similar, finds columns matching the regular expression pattern '"^..(ST|OR).*C$"'. data.frame method does not replace numeric columns that already exist.


billdenney/Rsdtm documentation built on Dec. 7, 2022, 2:11 a.m.