[R] Loss of precision in read.csv.
Joshua Wiley
jwiley.psych at gmail.com
Sat Oct 9 23:38:50 CEST 2010
Hi Steven,
As near as I can tell, no precision is lost. R is just being
courteous and not excessively filling our consoles. Try:
print(airports[1,"latitude_deg"], digits = 22)
which is the most digits R will print (although internally it can
store more I believe).
Alternately, you can convert it to character class:
as.character(airports[1, ])
So in short, this is just a cosmetic feature of presenting the data,
not its actual storage.
Cheers,
Josh
On Sat, Oct 9, 2010 at 1:33 PM, steven mosher <moshersteven at gmail.com> wrote:
> Given a csv file from this location
>
> Airports<-"http://www.ourairports.com/data/airports.csv"
>
> download.file(Airports,basename(Airports))
>
>
> airports <-read.csv("airports.csv",encoding="UTF-8")
>
>> airports[1,]
>
> id ident type name latitude_deg longitude_deg
> elevation_ft continent iso_country iso_region municipality scheduled_service
>
> 1 6523 00A heliport Total Rf Heliport *40.0708 -74.9336 *
> 11 <NA> US US-PA Bensalem no
>
> gps_code iata_code local_code home_link wikipedia_link keywords
>
> 1 00A 00A
>
>
> And the precision is lost which we can show by using readLines:
>
>
> fred<-readLines("airports.csv")
>
>> fred[2]
> [1] "6523,\"00A\",\"heliport\",\"Total Rf Heliport\",*
> 40.07080078125,-74.9336013793945*
> ,11,\"NA\",\"US\",\"US-PA\",\"Bensalem\",\"no\",\"00A\",,\"00A\",,,"
>
>
> I tried various approaches, using colClasses, switching to read.tables,
> specifying dec="."
>
>
> I tested read.csv and it does preserve precision on my test case, but not on
> this data.
>
>
> Ideas?
>
> [[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.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
More information about the R-help
mailing list