Learn R Programming

GWASTools (version 1.18.0)

allequal: Test if two objects have the same elements

Description

allequal tests if two objects have all the same elements, including whether they have NAs in the same place.

Usage

allequal(x, y)

Arguments

x
first object to compare
y
second object to compare

Value

Returns TRUE if x and y exist and all elements are equal, FALSE if some elements are unequal. If there are NA values, returns TRUE if is.na(x) == is.na(y) and all other elements are equal. Returns FALSE if is.na(x) != is.na(y). Retuns FALSE if x or y (but not both) is NULL.

Details

Unlike all(x == y), allequal will return FALSE if either object is NULL. Does not check class types, so allequal will return TRUE in some cases where identical will return FALSE (e.g. if two objects are identical when coerced to the same class). allequal always retuns a logical value, so it can be used safely in if expressions.

See Also

identical, all, all.equal

Examples

Run this code
x <- c(1,2,NA,4); y <- c(1,2,NA,4);
allequal(x, y) ## TRUE
allequal(1, as.integer(1)) ## TRUE
allequal(1, "1") ## TRUE

Run the code above in your browser using DataLab