[R] unexpected result from format(x, digits)
Duncan Murdoch
murdoch.duncan at gmail.com
Wed Apr 28 23:52:24 CEST 2010
On 28/04/2010 5:45 PM, Steve Taylor wrote:
>
> Is this a bug somewhere? The format function, using a specific number of digits, doesn't give sensible results:
>
I don't see the error. In all examples, the smallest value is 0.08953,
and it appears to be rendered to the requested number of significant
figures in each case. All the other numbers are rendered to match.
If you want to specify decimal places rather than significant digits,
you should probably use sprintf() rather than format().
Duncan Murdoch
>
> R> set.seed(2);print(x<-rexp(5))
> [1] 1.86535 0.40475 0.14665 1.73071 0.08953
> R> format(x,digits=1)
> [1] "1.87" "0.40" "0.15" "1.73" "0.09"
> R> format(x,digits=2)
> [1] "1.87" "0.40" "0.15" "1.73" "0.09"
> R> format(x,digits=3)
> [1] "1.8654" "0.4047" "0.1467" "1.7307" "0.0895"
>
>
>
> [[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.
>
More information about the R-help
mailing list