[R] Numbers with correct significant digits

2006-11-17 Thread RMan54
This, for example: v - c(9.6996, 99.99) formatC(v, digits=3, format=g) shows: 9.7 100 This is scientifically incorrect for the first number in the sense that I like to show all 3 significant digits, including trailing zero's. Is there a way that the first number would show as 9.70? By

Re: [R] Numbers with correct significant digits

2006-11-17 Thread RMan54
I think that I answered my own question. Since formatC is an implementation of the C-style formatting, I thought that a # as flag could work (for g and G conversions, trailing zeros are not removed from the result as they would otherwise be). Although not in the online help, this worked in R

Re: [R] Numbers with correct significant digits

2006-11-17 Thread Gabor Grothendieck
Try this where vf is the output of your format statement: gsub([.]\\B, , vf) Actually I was surprised at this as my reading of ?regex suggests it should have been \\b but when that did not work I tried \\B and that did work.I am using R version 2.4.0 Patched (2006-10-24 r39722) on Windows

Re: [R] Numbers with correct significant digits

2006-11-17 Thread Andrew Robinson
I have found that sprintf gets this right, although the syntax of the command itself is a little less clear. sprintf(%.2f, 9.6996) [1] 9.70 I hope that this helps, Andrew On Fri, Nov 17, 2006 at 02:14:58PM -0800, RMan54 wrote: This, for example: v - c(9.6996, 99.99) formatC(v,

Re: [R] Numbers with correct significant digits

2006-11-17 Thread RMan54
Yes, you can always tweak one number but it may mess up the others. That's why my example included two numbers. When you use sprintf this way: v - c(9.6996, 99.99) sprintf(%.2f, v) you get: 9.70 99.99 Now I have 4 significant digits for the 2nd number! The .2 in the format string always

Re: [R] Numbers with correct significant digits

2006-11-17 Thread Andrew Robinson
Nice solution. I believe that showing the decimal point is correct. It demonstrates that the number is not an integer. Cheers Andrew On Fri, Nov 17, 2006 at 02:43:10PM -0800, RMan54 wrote: I think that I answered my own question. Since formatC is an implementation of the C-style

Re: [R] Numbers with correct significant digits

2006-11-17 Thread Gabor Grothendieck
You must be thinking of some other language: is.integer(1) [1] FALSE On 11/17/06, Andrew Robinson [EMAIL PROTECTED] wrote: Nice solution. I believe that showing the decimal point is correct. It demonstrates that the number is not an integer. Cheers Andrew On Fri, Nov 17, 2006 at

Re: [R] Numbers with correct significant digits

2006-11-17 Thread Andrew Robinson
I meant that it demonstrates that the number is not an integer to the reader, regardless of how it is stored. In the reporting of measurements, 10 is interpreted as an integer, whereas 10. is interpreted as a real, rounded to two significant digits. Cheers Andrew On Fri, Nov 17, 2006 at