Re: [R] converting character strings to numbers

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 14 Jun 2007 22:26:34 -0400

See:

https://stat.ethz.ch/pipermail/r-help/2007-April/130912.html

On 6/14/07, Andrew J Tyre <atyre2_at_unlnotes.unl.edu> wrote:
> I have a comma delimited text file in which many columns of numbers are
> also quoted and have commas as well as decimals. I was surprised to find
> read.csv() didn't import this seamlessly, even after messing around with
> the colClasses argument. I did find a solution to convert the character
> strings after reading them in, but wonder if there isn't a better one I
> overlooked.
>
> test = c("10,522.5","11,768.9","11,354.3")
> as.numeric(test) # fails
> as.numeric(gsub(",","",test)) # works
>
> Any suggestions? Or is this as good as it gets? I'm not complaining ...
> just curious!
>
> Drew Tyre
>
> School of Natural Resources
> University of Nebraska-Lincoln
> 416 Hardin Hall, East Campus
> Lincoln, NE 68583-0974
> phone: +1 402 472 4054 fax: +1 402 472 2946
> email: atyre2_at_unl.edu
> http://snr.unl.edu/tyre
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch 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_at_stat.math.ethz.ch 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. Received on Fri 15 Jun 2007 - 02:34:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 15 Jun 2007 - 03:32:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.