I am trying to use round()to force R to display a specific number of decimals, but it seems to display <=2 decimals no matter what I specify in the digits argument. As an alternative I tried signif(), but it also produces unexpected results. See example code and results below. Format() works, but then the result no longer is numeric. Am I missing something simple? I am using R 2.9.0 on Windows XP. Thanks, Glenn
#code h=12345.16711 h round(h,digits=1) round(h,digits=2) round(h,digits=3) round(h,digits=4) round(h,digits=5) signif(h,digits=9) format(h,nsmall=4) #results > h=12345.16711 > h [1] 12345.17 > round(h,digits=1) [1] 12345.2 > round(h,digits=2) [1] 12345.17 > round(h,digits=3) [1] 12345.17 > round(h,digits=4) [1] 12345.17 > round(h,digits=5) [1] 12345.17 > signif(h,digits=9) [1] 12345.17 > > format(h,nsmall=4) [1] "12345.1671" ______________________________________________ R-help@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.