extract_num {clinpubr} | R Documentation |
Extract numbers from string.
Description
Extract numerical values from strings. Can be used to filter out the unwanted information coming along with the numbers.
Usage
extract_num(
x,
res_type = c("first", "range"),
multimatch2na = FALSE,
leq_1 = FALSE,
allow_neg = TRUE,
zero_regexp = NULL,
max_regexp = NULL,
max_quantile = 0.95
)
Arguments
x |
A character vector. |
res_type |
The type of the result. Can be |
multimatch2na |
If |
leq_1 |
If |
allow_neg |
If |
zero_regexp |
A regular expression to match the string that indicates zero. |
max_regexp |
A regular expression to match the string that indicates the maximum value. |
max_quantile |
The quantile of values to set the maximum value to. |
Details
The function uses regular expressions to extract numbers from strings. The regular expression used is
"-?[0-9]+\\.?[0-9]*|-?\\.[0-9]+"
, which matches any number that may have a decimal point and may have a
negative sign.
Value
A numeric vector.
Examples
x <- c("1.2(XXX)", "5-8POS", "NS", "FULL", "5.5", "4.2")
extract_num(x)
extract_num(x,
res_type = "first", multimatch2na = TRUE, zero_regexp = "NEG|NS",
max_regexp = "FULL"
)
extract_num(x, res_type = "range", allow_neg = FALSE, zero_regexp = "NEG|NS", max_regexp = "FULL")