[R] weird behavior of nsmall in format

From: Adrian Dragulescu <adrian_d_at_eskimo.com>
Date: Tue 14 Feb 2006 - 14:05:27 EST

>From the help page of format, nsmall should control the number of digits.

> format(0.123456789, nsmall = 10)
[1] "0.1234567890"
> format(0.123456789, nsmall = 1)

[1] "0.1234568"
> format(0.123456789, nsmall = 2)

[1] "0.1234568"
> format(0.123456789, nsmall = 8)

[1] "0.12345679"

It adds zeros fine but for format(0.123456789, nsmall = 1) I want the result to be 0.1.

I want to format numbers with a fixed number of digits. A combination of round and format + nsmall does the job. sprintf will do it too, but I wondered if the current implementation of nsmall in format is correct.

Thanks,

Adrian



R-help@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 Received on Tue Feb 14 14:11:03 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:29 EST