This drops any non-numeric characters before or after the first number. The grouping mark specified by the locale is ignored inside the number.
parse_number(x, na = c("", "NA"), locale = default_locale(), trim_ws = TRUE) col_number()
| x | Character vector of values to parse. |
|---|---|
| na | Character vector of strings to interpret as missing values. Set this
option to |
| locale | The locale controls defaults that vary from place to place.
The default locale is US-centric (like R), but you can use
|
| trim_ws | Should leading and trailing whitespace be trimmed from each field before parsing it? |
A numeric vector (double) of parsed numbers.
Other parsers:
col_skip(),
cols_condense(),
cols(),
parse_datetime(),
parse_factor(),
parse_guess(),
parse_logical(),
parse_vector()
## These all return 1000 parse_number("$1,000") ## leading $ and grouping character , ignored#> [1] 1000parse_number("euro1,000") ## leading non-numeric euro ignored#> [1] 1000parse_number("1,234.56")#> [1] 1234.56## explicit locale specifying European grouping and decimal marks parse_number("1.234,56", locale = locale(decimal_mark = ",", grouping_mark = "."))#> [1] 1234.56## SI/ISO 31-0 standard spaces for number grouping parse_number("1 234.56", locale = locale(decimal_mark = ".", grouping_mark = " "))#> [1] 1234.56#> [1] 1 2 3 NA#> [1] 1 2 3 NA NA