[R] how to calculate a numeric's digits count?

Duncan Murdoch murdoch.duncan at gmail.com
Fri Oct 24 12:36:04 CEST 2014


On 23/10/2014, 11:35 PM, PO SU wrote:
> 
> Dear usRers,
>   Now i want to cal ,e.g. 
>  cal(1.234)  will get 3
>  cal(1) will get 0
>  cal(1.3045) will get 4
>  But the difficult part is cal(1.3450) will get 4 not 3.
> So, is there anyone happen to know the solution to this problem, or it can't be solved in R, because 1.340 will always be transformed autolly to 1.34?
> 

No, there's no way to do what you want unless you put quotes around the
number.  R parses 1.345 and 1.3450 as exactly the same thing, whereas
"1.345" and "1.3450" are different.

Duncan Murdoch



More information about the R-help mailing list