[R] Converting dollar value (factors) to numeric

Ruihong Huang ruihong.lang.r at googlemail.com
Wed May 5 09:39:05 CEST 2010


If you use Linux, we can simply use "sed" (in Linux terminal, NOT R) to 
delete all leading '$' from the file "test.dat" by

$ sed -e 's/\$//g' test.dat > newdata.dat

And now R will read all this dollar as numeric.


Bests,
Ruihong

On 05/05/2010 09:16 AM, Wang, Kevin (SYD) wrote:
> Hi,
>
> I'm trying to read in a bunch of CSV files into R where many columns are
> coded like $111.11.  When reading them in they are treated as factors.
>
> I'm wondering if there is an easy way to convert them into numeric in R
> (as I don't want to modify the source data)?  I've done some searches
> and can't seem to find an easy way to do this.
>
> I apologise if this is a trivial question, I haven't been using R for a
> while.
>
> Many thanks in advance!
>
> Cheers
>
> Kev
>
> Kevin Wang
>    
>> Senior Advisor, Health and Human Services Practice
>> Government Advisory Services
>>
>> KPMG
>> 10 Shelley Street
>> Sydney  NSW  2000  Australia
>>
>> Tel 	+61 2 9335 8282
>> Fax	+61 2 9335 7001
>>
>>      
> kevinwang at kpmg.com.au
>
>    
>> Protect the environment: think before you print
>>
>>
>>      
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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