cnumeric | R Documentation |
This function takes characters that look like numbers
and converts them to numbers.
Its name is based on the VBA function CNumeric
.
It does some pre-processing before calling
as.numeric
.
converts factors
removes all whitespace
converts wrapping "()" to negatives
removes commas
converts percentages to decimals
calls as.numeric
cnumeric(v)
v |
a vector |
A vector of numerics. Returns NA
when conversion is not possible after application
of the rules above.
# Commas are removed
cnumeric(c('1,000,000', '2,000.03'))
# But, we don't check to make sure that
# commas are in the right place first
cnumeric(c('1,0,0', '2,0000.03'))
# Accounting-style negatives
cnumeric(c('(1,000.92)', '(4)'))
# Percents are converted
cnumeric(c('28.3%', '-1.3%', '(15%)'))
# If scientific notation is present, R knows what to do
cnumeric(c('3e7', '5e-1'))
# TODO it doesn't deal with currencies yet
cnumeric(c('USD 0.10', '$14.34'))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.