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

Linlin Yan yanlinlin82 at gmail.com
Wed Dec 16 10:37:18 CET 2009


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.isu at 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.




More information about the R-help mailing list