[R] Odp: How to read percentage and currency data?

Hrishi Mittal hrishimittal at gmail.com
Wed Feb 24 16:55:49 CET 2010


Removing the % signs by Ista's method works. However as I noted earlier, I
was hoping there was a more elegant solution which deals with percentage and
currency values without knowing about their presence beforehand. 

It's a shame that something which Excel deals with trivially is such a hack
in R. I'll try to delve deeper and write something which does this well. But
my knowledge is limited and I will probably come back for help.

For now, Henrique Dallazuanna provided me with the following solution using
the gsubfn package. Now if only I can get it to install....

Lines <- "Store   Year    Revenue
abc     2010    R$557889
def     2010    $D697356
ghi       2010    £321
jkl     2010    €21648"

d <- read.table(textConnection(Lines), header = TRUE)

colCurrency <- 'Revenue'
newD <- transform(d,
                 Revenue = strapply(as.character(d[,colCurrency]),
                                    pattern = "(\\w+\\W|\\W)|(\\d+)",
                                        backref = 1, simplify = rbind))

Try  http://prettygraph.com Pretty Graph , the easiest way to make R-powered
graphs on the web.
View this message in context: http://n4.nabble.com/How-to-read-percentage-and-currency-data-tp1567318p1567643.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list