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 for 3.1415, return '5'?
>
> Thanks in advance.

______________________________________________
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