floating_point_comparisons | R Documentation |
These are an important set of operators missing from base R. In particular,
using ==
on two non-interger numbers can give unexpected results (see examples.)
See this for details: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
x %~=% y
x %>~% y
x %<~% y
x |
numeric |
y |
numeric |
Ben Wiseman, benjamin.wiseman@kornferry.com
Other comparisons:
comparisons
## Floating point test of equality ####
# Basic Equality - no roperators:
(0.1 + 0.1 + 0.1) == 0.3 # FALSE
# Basic Equality - with roperators:
(0.1 + 0.1 + 0.1) %~=% 0.3 # TRUE
# NOTE: for floating point >= and <=
(0.1 + 0.1 + 0.1) %>=% 0.3 # TRUE
(0.1 + 0.1 + 0.1) %<=% 0.3 # FALSE
# Use >~ and <~ for greater/less than or approx equal
(0.1 + 0.1 + 0.1) %>~% 0.3 # TRUE
(0.1 + 0.1 + 0.1) %<~% 0.3 # TRUE
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.