parse_number

0th

Percentile

Parse numbers, flexibly

This drops any non-numeric characters before or after the first number. The grouping mark specified by the locale is ignored inside the number.

Usage
parse_number(x, na = c("", "NA"), locale = default_locale(),
  trim_ws = TRUE)

col_number()

Arguments
x

Character vector of values to parse.

na

Character vector of strings to interpret as missing values. Set this option to character() to indicate no missing values.

locale

The locale controls defaults that vary from place to place. The default locale is US-centric (like R), but you can use locale() to create your own locale that controls things like the default time zone, encoding, decimal mark, big mark, and day/month names.

trim_ws

Should leading and trailing whitespace be trimmed from each field before parsing it?

Value

A numeric vector (double) of parsed numbers.

See Also

Other parsers: col_skip, cols_condense, cols, parse_datetime, parse_factor, parse_guess, parse_logical, parse_vector

Aliases
  • parse_number
  • col_number
Examples
# NOT RUN {
parse_number("$1000")
parse_number("1,234,567.78")
# }
Documentation reproduced from package readr, version 1.2.1, License: GPL (>= 2) | file LICENSE

Community examples

davidsmi@microsoft.com at Apr 7, 2017 readr v1.1.0

```r ### Explicitly specify grouping and decimal marks with locale() > parse_number("123.456,789", locale=locale(grouping_mark=".", decimal_mark=",")) [1] 123456.8 ```