DescTools (version 0.99.8.1)

StrVal: Extract All Numbers From a String

Description

Extract all numbers from a string, using a regular expression.

Usage

StrVal(x)

Arguments

x
a character vector

Value

  • depending on the results the function will return either a character vector, in the case every element of x contained only one number, or a list of character vectors containing the found numbers.

See Also

other string functions, e.g. StrTrunc

Examples

Run this code
# a simple vector with only one number per element
StrVal(x=c("week 1", "week 3", "week 4", "week 5"))

# several numbers per element
StrVal(x=c("This is 1. place: 45.2", "none", "12.1 but -2.7 follow, 10.2e23 "))

Run the code above in your browser using DataCamp Workspace