if条件超过1的语句

时间:2018-04-13 21:22:26

标签: r

码(伪)

x = c('Gender','Employee Status')
y = c('Gender','Employee Status','Tenure')
if (!(x %in% y)){do this}
else(do this)

我知道if没有矢量化,而ifelse却是ifelse给了我一些错误。我使用的功能。有没有办法让if矢量化以接受上面的多个输入?这样做并且这是一系列步骤。

1 个答案:

答案 0 :(得分:0)

您可以使用设置表示法来检查X是否在Y

之内
# Setup
x <- c('Gender','Employee Status')
y <- c('Gender','Employee Status','Tenure')

# Check X in Y
if (identical(setdiff(x, y), character(0))) {
    print("All of X in Y")
} else {
    print("Not all of X in Y")
}