Learn R Programming

teal.modules.clinical (version 0.10.0)

as_num: Parse text input to numeric vector

Description

Generic to parse text into numeric vectors. This was initially designed for a robust interpretation of text input in teal modules.

Usage

as_num(str)

# S3 method for default as_num(str)

# S3 method for character as_num(str)

# S3 method for numeric as_num(str)

# S3 method for factor as_num(str)

# S3 method for logical as_num(str)

Value

As vector of numeric if directly parsed from numeric or boolean. A list of numeric if parsed from a character string, each character string associated with an list item.

Arguments

str

(vector)
to extract numeric from.

Details

The function is intended to extract any numeric from a character string, factor levels, boolean and return a vector of numeric.

Examples

Run this code
dta <- list(
  character = c("text10,20.5letter30.!", "!-.40$$-50e5[", NA),
  factor    = factor(c("]+60e-6, 7.7%%8L", "%90sep.100\"1L", NA_character_)),
  numeric   = c(1, -5e+2, NA),
  logical   = c(TRUE, FALSE, NA)
)
lapply(dta, as_num)

Run the code above in your browser using DataLab