[R] specify the number of decimal numbers
James W. MacDonald
jmacdon at med.umich.edu
Thu May 14 17:15:16 CEST 2009
Wacek Kusnierczyk wrote:
> (Ted Harding) wrote:
>> On 14-May-09 12:27:40, Wacek Kusnierczyk wrote:
>>
>>> ... but remember that sprintf introduces excel bugs into r (i.e.,
>>> rounding is not done according to the IEC 60559 standard, see ?round):
>>>
>>> ns = c(0.05, 0.15)
>>> round(ns, 1)
>>> # 0.0 0.2
>>> as.numeric(sprintf('%.1f', ns))
>>> # 0.1 0.1
>>> vQ
>>>
>> True! And thanks for importing that point into the discussion.
>>
>
> said but true, true but sad. i have already raised the issue on this
> list earlier, but to no response. apparently, this sort of excel bug in
> r is an intentional feature, so you may not get it improved anytime
> soon. unless you submit a patch and get it accepted, that is.
Have you brought this 'issue' up with the Perl people as well?
perl -e 'print sprintf("%.1f", 0.05) . "\n";'
0.1
perl -e 'print sprintf("%.1f", 0.15) . "\n";'
0.1
>
> vQ
>
> ______________________________________________
> 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.
--
James W. MacDonald, M.S.
Biostatistician
Douglas Lab
University of Michigan
Department of Human Genetics
5912 Buhl
1241 E. Catherine St.
Ann Arbor MI 48109-5618
734-615-7826
More information about the R-help
mailing list