[R] How many digits are there in left of dot of 0.0001 ?

JS Huang js.huang at protective.com
Thu Feb 26 03:52:50 CET 2015


Hi,

  I assume you want to know the digit count to the left of decimal point. 
If this is the case, then you may use  trunc(log10(max(1,trunc(abs(a)))))+1
for a numerical variable a.  Count 0.12 as having one digit to the left of
decimal point.

> trunc(log10(max(1,trunc(abs(-100000.99)))))+1
[1] 6
> trunc(log10(max(1,trunc(abs(0)))))+1
[1] 1
> trunc(log10(max(1,trunc(abs(9.999)))))+1
[1] 1
> trunc(log10(max(1,trunc(abs(19.999)))))+1
[1] 2
> trunc(log10(max(1,trunc(abs(-1999.999)))))+1
[1] 4



--
View this message in context: http://r.789695.n4.nabble.com/How-many-digits-are-there-in-left-of-dot-of-0-0001-tp4703842p4703847.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list