R Users:

  Can anyone please help me with the following:
  I'm unclear as to how to get format to do what I want.
  I've tried the following and get unexpected results.

Input.....
val<-321.6

format(val, digits=1)
format(val, digits=2) 
format(val, digits=3)
format(val, digits=4)
format(val, digits=5)

Output....

[1] "322"
[1] "322"
[1] "322"
[1] "321.6"
[1] "321.6"

Whereas I would expect to get...

[1] "300"
[1] "320"
[1] "322"
[1] "321.6"
[1] "321.60"

since "digits" is defined as the number of "significant digits".  The number 
321.6 shown to 1 significant digit should be 300., not 322 which is 3 
significant digits!  Likewise for the other cases.

Can anyone explain what format() is doing? 


Regards, 
Michael

______________________________________________
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.

Reply via email to