I'm importing sales data that needs to be converted from character strings to numeric.
I'm trying to use parse_number
in readr
to do this, but it throws a parsing error for negative values, and coerces them to NA
s.
As an example:
x <- c("$1,000.00", "$500.00", "-$200.00")
y <- parse_number(x)
Warning: 1 parsing failure.
row # A tibble: 1 x 4 col row col expected actual expected <int> <int> <chr> <chr> actual 1 3 NA a number -
y
[1] 1000 500 NA
Does parse_number
or readr
have functionality that allows me to keep "-" for negative currency values?
(I'm not asking for an as.numeric(gsub())
solution.)