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

Petr PIKAL petr.pikal at precheza.cz
Wed Feb 24 17:28:18 CET 2010


Hi

r-help-bounces at r-project.org napsal dne 24.02.2010 16:55:49:

> 
> Petr,
> 
> 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.

I believe that if you introduce a new class which could specify currencies 
you could write methods for handling them. But it is beyond my knowledge 
and somebody else has to answer it.

One question immediately rise how would you handle different currencies in 
one column (I believe that even Excel could have troubles with different 
currencies in one document).

Regards
Petr


> 
> 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)
> closeAllConnections()
> 
> colCurrency <- 'Revenue'
> library(gsubfn)
> newD <- transform(d,
>                  Revenue = strapply(as.character(d[,colCurrency]),
>                                     pattern = "(\\w+\\W|\\W)|(\\d+)",
>                                         backref = 1, simplify = rbind))
> newD
> 
> -----
> 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.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list