dplyr: error message

hello,
I have a question please but i cannot upload the data due to the size. I try to filter but got Something i Don't understand.
data2<-data1[which(data1$product==c(65,85) & data1$year==c(2020,2024)),] => no error message
data2<-data1[which(data1$product==c(65,85) & data1$year==c(2021:2024)),] => error message :" data1$year== c(2021:2024) : longer object length is not a multiple of shorter object length"

=> dataset is huge so it's complicated to see what's happen, should i filter out outliers, NAs, etc.? Thank you.

Quite possibly data1$year==c(2021:2024)) doesn't mean what you intend. You are comparing each element of data1$year to a vector of four numbers. Perhaps you want data1$year %in% c(2021:2024)).

Hello,
Thanks a lot. I see it might a reason that i will explore and come back to tell you. I also noticed (not visible here) that some of my numbers are not numeric so it might create difficulty. Come back tomorow with results. Thanks again.

This works: 1:4 + 1
This works too: 1:4 + 1:2
This works not: 1:4 + 1:3

Why?

When combining two vectors of unequal length, R makes them of equal length. This only works, if the length of the longer vector is a multiple of the length of the shorter vector.

For the first two examples, this condition is true.
For the next example this is not true.

In the latter case, you get the message as longer object length is not a multiple of shorter object length

Thank you for your reply.