Dear all I have a txt file with the following contents 1 50.7906430000000 6.06349800000000 2 50.7907380000000 6.06347100000000 3 50.7910810000000 6.06338000000000 4 50.7911890000000 6.06355200000000 I am usind read.table('myfile.txt',sep=" ") which unfortunately returns only integers and not doubles that are required to store theĀ 50.7906430000000 What can I do to force it to store things into doubles? B.R Alex [[alternative HTML version deleted]]
R. Michael Weylandt <michael.weylandt@gmail.com>
2011-Nov-17 17:29 UTC
[R] read.table with double precision
I'm having trouble replicating/understanding why that would happen since I do it all the time. The only thing that raises a hint of suspicion is using the blank space separator , but I'm pretty sure that's fine What does str() give? Possibly factors? If you are sure that's happening as described, can you send a sample .txt ( won't get scrubbed) and your exact import code? Michael On Nov 17, 2011, at 11:49 AM, Alaios <alaios at yahoo.com> wrote:> Dear all I have a txt file with the following contents > 1 50.7906430000000 6.06349800000000 > 2 50.7907380000000 6.06347100000000 > 3 50.7910810000000 6.06338000000000 > 4 50.7911890000000 6.06355200000000 > > > I am usind read.table('myfile.txt',sep=" ") > > which unfortunately returns only integers and not doubles that are required to store the? > > 50.7906430000000 > > What can I do to force it to store things into doubles? > > B.R > Alex > > [[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.
Hi, On Thu, Nov 17, 2011 at 11:49 AM, Alaios <alaios at yahoo.com> wrote:> Dear all I have a txt file with the following contents > 1 50.7906430000000 6.06349800000000 > 2 50.7907380000000 6.06347100000000 > 3 50.7910810000000 6.06338000000000 > 4 50.7911890000000 6.06355200000000 > > > I am usind read.table('myfile.txt',sep=" ") > > which unfortunately returns only integers and not doubles that are required to store the > > 50.7906430000000Using that exact file you included? If so, then I suspect you are confusing display and storage, though even then my default session doesn't show integers. How do you know that it is returning only integers? What is options()$digits set to?> myfileV1 V2 V3 1 1 50.790643 6.063498 2 2 50.790738 6.063471 3 3 50.791081 6.063380 4 4 50.791189 6.063552> sprintf("%2.10f", myfile[1,2])[1] "50.7906430000"> What can I do to force it to store things into doubles?What is str(myfile) ? Sarah -- Sarah Goslee http://www.functionaldiversity.org