假设我有这两个DF。
df1 <- c("A","B","C","D") #The problem is D (both DFs have a different number of rows)
df2 <- c("A","B","Z")
我的目标是根据df1和df2中的值在df3中创建一个新变量。所以,如果df1 = df2那么&#34; Y&#34;别的&#34; N&#34;。
df3$new_var <- ifelse(df1==df2, "Y","N")
运行代码时收到此警告消息。显然,如果我在df1中摆脱D,那就没问题了。
Warning message:
In df1 == df2 :
longer object length is not a multiple of shorter object length
答案 0 :(得分:2)
我们可以在没有ifelse
c("N", "Y")[(df1%in% df2)+1]
#[1] "Y" "Y" "N" "N"