Petr and Rob, I apologise for complicating my question further. Having more than one currency in the same column is no doubt inconsistent. For now, I'm happy to have a solution for reading single currencies or percentage values in separate columns. I will use string replacement until I can think of a better way.
On 24 February 2010 16:48, Rob Forler <rfor...@uchicago.edu> wrote: > This seems like a case where you should have a column that is "Currency" or > "CurrencyKey". > > You can then do proper sql like queries on the data and convert into a base > currency or something to do column wise operations. > > A column of data should be somehow "consistent" within some view. Currently > your column of different currencies is consistent in no view. > > > > > On Wed, Feb 24, 2010 at 10:28 AM, Petr PIKAL <petr.pi...@precheza.cz>wrote: > >> Hi >> >> r-help-boun...@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@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. >> >> ______________________________________________ >> R-help@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. >> > > [[alternative HTML version deleted]]
______________________________________________ R-help@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.