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
Why?
Fixing this problem is quite easy! All you need to do is make sure that the vectors are the same length. When you only have two vectors, it is also easy to make sure the larger length is a multiple of the smaller. This solution becomes more difficult when you use more than two vectors.
One common warning message you may encounter in R is: Warning message: In a + b : longer object length is not a multiple of shorter object length. This warning message occurs when you attempt to perform some operation across two or more vectors that don't have the same length.
You don't give a reproducible example but your warning message tells you exactly what the problem is.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With