R语言 检查两个对象是否相等 – setequal() 函数
R语言中的 setequal() 函数是用来检查两个对象是否相等的。该函数以两个对象(如矢量、数据帧等)为参数,如果对象相等,则结果为 “true “或 “false”。
语法: setequal(x, y)
参数:
x和y: 具有项目序列的对象
例1 :
# R program to illustrate
# the use of setequal() function
# Vector 1
x1 <- c(1, 2, 3, 4, 5, 6)
# Vector 2
x2 <- c(1:6)
# Vector 3
x3 <- c(2, 3, 4, 5, 6)
# Calling setequal() Function
setequal(x1, x2)
setequal(x1, x3)
输出
[1] TRUE
[1] FALSE
例2 :
# R program to illustrate
# the use of setequal() function
# Data frame 1
data_x <- data.frame(x1 = c(5, 6, 7),
x2 = c(2, 2, 2))
# Data frame 2
data_y <- data.frame(y1 = c(5, 6, 7),
y2 = c(2, 2, 2))
# Calling setequal() Function
setequal(data_x, data_y)
输出
[1] TRUE