[R] strangely long floating point with write.table()

David Winsemius dwinsemius at comcast.net
Sat Mar 15 07:46:59 CET 2014


Post output from:

dput(data2)

My guess is the 3rd column is a factor vector.
-- 
David

Sent from my iPhone

> On Mar 15, 2014, at 12:03 PM, Mike Miller <mbmiller+l at gmail.com> wrote:
> 
>> On Fri, 14 Mar 2014, Duncan Murdoch wrote:
>> 
>>> On 14-03-14 8:59 PM, Mike Miller wrote:
>>> What I'm using:
>>> R version 3.0.1 (2013-05-16) -- "Good Sport"
>>> Copyright (C) 2013 The R Foundation for Statistical Computing
>>> Platform: x86_64-unknown-linux-gnu (64-bit)
>> 
>> That's not current, but it's not very old...
>> 
>>> According to some docs, options(digits) controls numerical precision in output of write.table().  I'm using the default value for digits:
>>>> getOption("digits")
>>> [1] 7
>>> I have a bunch of numbers in a data frame that are only a few digits to the right of the decimal:
>> 
>> That's not enough to reproduce this.  Put together a self-contained reproducible example if you're wondering why something behaves as it does. With just a bunch of output, you'll just get uninformed guesses.
> 
> 
> Thanks for the tip.  Here's what I've done:
> 
>> data2 <- data[c(94,120),c(18,20,21)]
>> save(data2, file="data2.Rdata")
>> q("no")
> 
> $ R
>> load("data2.Rdata")
>> data2
>      V18   V20      V21
> 94  0.008 0.008 0.000064
> 120 0.023 0.023 0.000529
>> write.table(data2, file="data2.txt", sep="\t", row.names=F, col.names=F)
> 
> $ cat data2.txt
> 0.00800000000000001     0.00800000000000001     6.40000000000001e-05
> 0.0229999999999999      0.0229999999999999      0.000528999999999996
> 
> The data2.Rdata file is attached to this message.
> 
> I guess that is enough to reproduce this exact finding.  I don't know how it works in general.
> 
> I don't have a newer version of R available right now.  It did the same thing on an older version (2.15.1).
> 
> Interestingly, on a different machine with an even older version (2.12.2) I see something a little different:
> 
> 0.008   0.008   6.40000000000001e-05
> 0.0229999999999999      0.0229999999999999      0.000528999999999996
> 
> Best,
> Mike
> ______________________________________________
> 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