num_equal {ds4psy}R Documentation

Test two numeric vectors for pairwise (near) equality.

Description

num_equal tests if two numeric vectors x and y are pairwise equal (within some tolerance value 'tol').

Usage

num_equal(x, y, tol = .Machine$double.eps^0.5)

Arguments

x

1st numeric vector to compare (required, assumes a numeric vector).

y

2nd numeric vector to compare (required, assumes a numeric vector).

tol

Numeric tolerance value. Default: tol = .Machine$double.eps^0.5 (see ?.Machine for details).

Details

num_equal is a safer way to verify the (near) equality of numeric vectors than ==, as numbers may exhibit floating point effects.

See Also

is_equal function for generic vectors; all.equal function of the R base package; near function of the dplyr package.

Other numeric functions: base2dec(), base_digits, dec2base(), is_equal(), is_wholenumber(), num_as_char(), num_as_ordinal()

Other utility functions: base2dec(), base_digits, dec2base(), is_equal(), is_vect(), is_wholenumber(), num_as_char(), num_as_ordinal()

Examples

num_equal(2, sqrt(2)^2)

# Recycling: 
num_equal(c(2, 3), c(sqrt(2)^2, sqrt(3)^2, 4/2, 9/3))

# Contrast:
.1 == .3/3
num_equal(.1, .3/3)

# Contrast:
v <- c(.9 - .8, .8 - .7, .7 - .6, .6 - .5, 
       .5 - .4, .4 - .3, .3 - .2, .2 -.1, .1)
unique(v)
.1 == v
num_equal(.1, v)
 

[Package ds4psy version 1.0.0 Index]