is_equal: Test two vectors for pairwise (near) equality.

View source: R/num_util_fun.R

is_equalR Documentation

Test two vectors for pairwise (near) equality.

Description

is_equal tests if two vectors x and y are pairwise equal.

Usage

is_equal(x, y, ...)

Arguments

x

1st vector to compare (required).

y

2nd vector to compare (required).

...

Other parameters (passed to num_equal()).

Details

If both x and y are numeric, is_equal calls num_equal(x, y, ...) (allowing for some tolerance threshold tol).

Otherwise, x and y are compared by x == y.

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

See Also

num_equal function for comparing numeric vectors; all.equal function of the R base package; near function of the dplyr package.

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

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

Examples


# numeric data: 
is_equal(2, sqrt(2)^2)
is_equal(2, sqrt(2)^2, tol = 0)
is_equal(c(2, 3), c(sqrt(2)^2, sqrt(3)^2, 4/2, 9/3))

# other data types:
is_equal((1:3 > 1), (1:3 > 2))                         # logical
is_equal(c("A", "B", "c"), toupper(c("a", "b", "c")))  # character
is_equal(as.Date("2020-08-16"), Sys.Date())            # dates

# as factors:
is_equal((1:3 > 1), as.factor((1:3 > 2)))  
is_equal(c(1, 2, 3), as.factor(c(1, 2, 3)))
is_equal(c("A", "B", "C"), as.factor(c("A", "B", "C"))) 
 

ds4psy documentation built on Sept. 15, 2023, 9:08 a.m.