number_format | R Documentation |
Convenience function to check layout of numbers stored as a character vector.
number_format(x, format = NULL, min_dig = NULL, max_dig = NULL, dec = ".")
x |
|
format |
|
min_dig |
|
max_dig |
|
dec |
|
If format
is specified, then min_dig
, max_dig
and dec
are ignored.
Numerical formats can be specified as a sequence of characters. There are a few special characters:
d
Stands for digit.
*
(digit globbing) zero or more digits
Here are some examples.
"d.dd" | One digit, a decimal point followed by two digits. |
"d.ddddddddEdd" | Scientific notation with eight digits behind the decimal point. |
"0.ddddddddEdd" | Same, but starting with a zero. |
"d,dd*" | one digit before the comma and at least two behind it. |
Other format-checkers:
field_format()
,
field_length()
df <- data.frame(number = c("12.34","0.23E55","0.98765E12"))
rules <- validator(
number_format(number, format="dd.dd")
, number_format(number, "0.ddEdd")
, number_format(number, "0.*Edd")
)
out <- confront(df, rules)
values(out)
# a few examples, without 'validator'
number_format("12.345", min_dig=2) # TRUE
number_format("12.345", min_dig=4) # FALSE
number_format("12.345", max_dig=2) # FALSE
number_format("12.345", max_dig=5) # TRUE
number_format("12,345", min_dig=2, max_dig=3, dec=",") # TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.