Description Usage Arguments Value Note References Examples
View source: R/replace_number.R
Replaces numeric represented numbers with words (e.g., 1001 becomes one thousand one).
1 | replace_number(x, num.paste = FALSE, remove = FALSE, ...)
|
x |
The text variable. |
num.paste |
logical. If |
remove |
logical. If |
... |
Other arguments passed to |
Returns a vector with numbers replaced.
The user may want to use replace_ordinal
first to remove ordinal number notation. For example
replace_number
would turn "21st" into
"twenty onest", whereas replace_ordinal
would
generate "twenty first".
Fox, J. (2005). Programmer's niche: How do you spell that number? R News. Vol. 5(1), pp. 51-55.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | x <- c(
NA,
'then .456 good',
'none',
"I like 346,457 ice cream cones.",
"I like 123456789 cashes.",
"They are 99 percent good and 45678.2345667"
)
replace_number(x)
replace_number(x, num.paste = TRUE)
replace_number(x, remove=TRUE)
## Not run:
library(textclean)
hunthou <- replace_number(seq_len(1e5))
textclean::mgsub(
"'twenty thousand three hundred five' into 20305",
hunthou,
seq_len(1e5)
)
## "'20305' into 20305"
## Larger example from: https://stackoverflow.com/q/18332463/1000343
## A slower approach
fivehunthou <- replace_number(seq_len(5e5))
testvect <- c("fifty seven", "four hundred fifty seven",
"six thousand four hundred fifty seven",
"forty six thousand four hundred fifty seven",
"forty six thousand four hundred fifty seven",
"three hundred forty six thousand four hundred fifty seven"
)
textclean::mgsub(testvect, fivehunthou, seq_len(5e5))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.