extract_numeric

0th

Percentile

Extract numeric component of variable.

This uses a regular expression to strip all non-numeric character from a string and then coerces the result to a number. This is useful for strings that are numbers with extra formatting (e.g. $1,200.34).

Usage
extract_numeric(x)
Arguments
x
A character vector (or a factor).
Aliases
  • extract_numeric
Examples
extract_numeric("$1,200.34")
extract_numeric("-2%")

# The heuristic is not perfect - it won't fail for things that
# clearly aren't numbers
extract_numeric("-2-2")
extract_numeric("12abc34")
Documentation reproduced from package tidyr, version 0.4.1, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.