[R] How to find the significant digits of a number?

2009-12-16 Thread Xiang Wu
Is there a function in R that could find the significant digit of a specific number? Such as for 3.1415, return '5'? Thanks in advance. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] How to find the significant digits of a number?

2009-12-16 Thread Gustaf Rydevik
On Wed, Dec 16, 2009 at 10:26 AM, Xiang Wu xiang@gmail.com wrote: Is there a function in R that could find the significant digit of a specific number? Such as for 3.1415, return '5'? Thanks in advance. [[alternative HTML version deleted]]

Re: [R] How to find the significant digits of a number?

2009-12-16 Thread Romain Francois
On 12/16/2009 10:26 AM, Xiang Wu wrote: Is there a function in R that could find the significant digit of a specific number? Such as for 3.1415, return '5'? Thanks in advance. Not sure to understand what you mean, but you can have a look at ?signif Something like this perhaps: foo -

Re: [R] How to find the significant digits of a number?

2009-12-16 Thread Linlin Yan
Try this: f - function(x) length(gregexpr([[:digit:]], as.character(x))[[1]]) f(3.14) [1] 3 f(3.1415) [1] 5 f(3.14159265) [1] 9 On Wed, Dec 16, 2009 at 1:39 PM, Xiang Wu xiang@gmail.com wrote: Is there a function in R that could find the significant digit of a specific number? Such as

Re: [R] How to find the significant digits of a number?

2009-12-16 Thread Duncan Murdoch
On 16/12/2009 12:39 AM, Xiang Wu wrote: Is there a function in R that could find the significant digit of a specific number? Such as for 3.1415, return '5'? The question may not have an unambiguous answer: I would say 1.00 and 1.0 have a different number of significant digits, but once

Re: [R] How to find the significant digits of a number?

2009-12-16 Thread Duncan Murdoch
On 16/12/2009 8:48 AM, Xiang Wu wrote: Yes, that's true. But what I need is the original precision of a numeric. So to me, 1.00 and 1. are different. In that case, they are not numbers, but strings: and you can probably use nchar() to count characters, after stripping off any leading or

[R] How to find the significant digits of a number?

2009-12-15 Thread Xiang Wu
Is there a function in R that could find the significant digit of a specific number? Such as for 3.1415, return '5'? Thanks in advance. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list