Learn R Programming

HelpersMG (version 6.2)

similar: Test if two vectors contains the same elements independently of their order

Description

Return TRUE only if all elements of x are present and only once in y.

Usage

similar(x, y, test.names = FALSE)

Value

A logical TRUE or FALSE

Arguments

x

A vector with numeric or character elements

y

A vector with numeric or character elements

test.names

Logical. If TRUE, the names of the vector elements must be also identical and unique

Author

Marc Girondot marc.girondot@gmail.com

Examples

Run this code
if (FALSE) {
A <- c("A", "B", "C", "D")
B <- c("A", "B", "C", "D")
similar(A, B)
similar(B, A)
A <- c(x="A", y="B", z="C", k="D")
B <- c(x="A", y="B", z="C", l="D")
similar(B, A)
similar(A, B, test.names=TRUE)
A <- c(x="A", y="B", z="C", k="D")
B <- c(x="A", z="C", k="D", y="B")
similar(B, A)
similar(A, B, test.names=TRUE)
}

Run the code above in your browser using DataLab