parseDollars: Convert character string with Dollar signs and commas to...

Description Usage Arguments Details Value Author(s) See Also Examples

Description

as.numeric of character strings after suppressing commas and dollar signs. This is a special case of parseCommas.

Usage

1
parseDollars(x, pattern='\\$|,', replacement='', ...)

Arguments

x

vector of character strings to be converted to numerics

pattern

regular expression to be replaced by replacement

replacement

Character string to substitute for each occurrence of pattern

...

optional arguments to pass to gsub

Details

as.numeric(gsub(x, ...)). See also parseCommas.

Value

Numeric vector converted from x.

Author(s)

Spencer Graves

See Also

gsub as.numeric parseCommas

Examples

 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)

Ecfun documentation built on Oct. 25, 2016, 12:19 p.m.

Search within the Ecfun package
Search all R packages, documentation and source code