[R] Odp: How to read percentage and currency data?
Petr PIKAL
petr.pikal at precheza.cz
Wed Feb 24 13:00:57 CET 2010
Hi
r-help-bounces at r-project.org napsal dne 24.02.2010 12:15:04:
>
> I'm struggling to find any help on this seemingly simple question - how
does
> one read data with percentage (%) or currency (£,$ etc.) signs? When I
try
> to read a data file which has any of those symbols in the data fields,
they
> are read as characters rather than values. Is there a function or
library
> which can deal with such values?
One option is read them as they are. You will get factors (or character
data with correct parameters setting)
as.numeric(Sale1, 1, nchar(Sale1-1))
You shall wrap this into lapply/sapply if you want to apply it to columns
of data frame.
Regards
Petr
>
> As an example, I use this sample from one of chinna's questions:
>
> Store Year Revenue
> abc 2010 $557889
> def 2010 $697356
>
> Similarly, for percentage values:
>
> Product Sale1 Sale2 Sale3 Sale4 Sale5 Sale6 Sale7
> A 101.00% 93.00% 85.00% 65.00% 74.00% 102.00% 119.00%
> B 585.00% 484.00% 599.00% 653.00% 726.00% 882.00% 1035.00%
> C 18.00% 19.00% 25.00% 15.00% 31.00% 33.00% 33.00%
> D 23.00% 22.00% 31.00% 30.00% 36.00% 42.00% 49.00%
> E 35.00% 41.00% 49.00% 40.00% 48.00% 48.00% 53.00%
> F 19.00% 20.00% 33.00% 16.00% 20.00% 26.00% 28.00%
>
>
> -----
> 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-tp1567318p1567318.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