[R] Number of digits of a value for problem 7.31 RFAQ

From: Matthieu Stigler <stigler3_at_etu.unige.ch>
Date: Mon, 18 Feb 2008 13:17:12 +0100

Hello dear R users!

I did not find a function which gives information about the number of digits of a value shown by R.
Do you know one?

I need it to solve the problem (see RFAQ 7.31)that 0.2==0.2+0.1-0.1 FALSE The solution suggested in RFAQ is to use isTRUE(all.equal(0.2,0.2+0.1-0.1))

But if I want to compare inequality:
0.2<=0.2 +0.1-0.1 TRUE
but 0.2<=0.2 +0.1-0.1 FALSE
but in this case all.equal does not work I think... Unless to write a double condition like
0.2>0.2 +0.1-0.1 | isTRUE(all.equal(0.2,0.2 +0.1-0.1))

The solution I found is to round the values, because 0.2==round(0.2+0.1-0.1,2) TRUE
However, one has to know the number of digits of the target value. How can you do when it is unknown?

What I mean is if R shows 2.3456 I want to obtain the info that digits=4 even if in facts the value has more (internal) digits.

I did not find a way to represent the number of digits but I found that as.numeric(as.character(x)) rounds the values to the number of digits shown. But is there a better way to make it?


R-help_at_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. Received on Mon 18 Feb 2008 - 12:19:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 18 Feb 2008 - 13:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive