为什么我会收到“警告较长的物体长度不是较短物体长度的倍数"? [英] Why do I get "warning longer object length is not a multiple of shorter object length"?
问题描述
我有数据框 dih_y2.这两行给了我一个警告:
I have dataframe dih_y2. These two lines give me a warning:
> memb = dih_y2$MemberID[1:10]
> dih_col = which(dih_y2$MemberID == memb)
Warning message:
In dih_y2$MemberID == memb :
longer object length is not a multiple of shorter object length
为什么?
推荐答案
您没有给出可重现的示例,但您的警告消息会准确地告诉您问题所在.
You don't give a reproducible example but your warning message tells you exactly what the problem is.
memb
只有 10 的长度.我猜dih_y2$MemberID
的长度不是 10 的倍数.当使用 ==
,如果不是倍数,R 会发出警告,让您知道它可能没有做您期望它做的事情.==
对元素进行相等性检查.我怀疑您想要做的是找到 dih_y2$MemberID
的哪些元素也在向量 memb
中.为此,您需要使用 %in%
运算符.
memb
only has a length of 10. I'm guessing the length of dih_y2$MemberID
isn't a multiple of 10. When using ==
, R spits out a warning if it isn't a multiple to let you know that it's probably not doing what you're expecting it to do. ==
does element-wise checking for equality. I suspect what you want to do is find which of the elements of dih_y2$MemberID
are also in the vector memb
. To do this you would want to use the %in%
operator.
dih_col <- which(dih_y2$MemeberID %in% memb)
这篇关于为什么我会收到“警告较长的物体长度不是较短物体长度的倍数"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!