Description Usage Arguments Details Value Author(s) See Also Examples
as.numeric of character strings after suppressing commas and dollar
signs. This is a generalization of parseDollars
.
1 2 3 4 5 6 7 8 | parseCommas(x, pattern='\\$|,', replacement='',
acceptableErrorRate=0, ...)
## Default S3 method:
parseCommas(x, pattern='\\$|,', replacement='',
acceptableErrorRate=0, ...)
## S3 method for class 'data.frame'
parseCommas(x, pattern='\\$|,', replacement='',
acceptableErrorRate=0, ...)
|
x |
vector of character strings to be converted to numerics |
pattern |
regular expression to be replaced by |
replacement |
Character string to substitute for each occurrence of |
acceptableErrorRate |
number indicating the proportion of new NAs to that can be introduced and still assume it's numeric |
... |
optional arguments to pass to |
as.numeric(gsub(x, ...))
The data.frame
method outputs another
data.frame
with character or factor columns connverted
to numerics using parseDollars
whenever that can be done
without creating NA
s.
Numeric vector converted from the character strings in x
or a
data.frame
with columns that are obviously numbers in
character format converted to numerics.
Spencer Graves
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ##
## 1. a character vector
##
X2 <- c('-$2,500', '$5,000.50')
x2 <- parseDollars(X2)
all.equal(x2, c(-2500, 5000.5))
##
## A data.frame
##
chDF <- data.frame(let=letters[1:2], Dol=X2, dol=x2)
numDF <- parseCommas(chDF)
chkDF <- chDF
chkDF$Dol <- x2
all.equal(numDF, chkDF)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.