Dplyr filter function gives invalid data

I have the following dataset: (sample)

    Team    Job Question    Answer
1   1        1     2             1
2   1        1     3a            2
3   1        1     3b            2
4   1        1     4a            1
5   1        1     4b            1

      

and I have 21 commands, so there are many lines. I'm trying to filter the command lines that did a good job in my experiment (with the dplyr package):

q10best <- filter(quest,Team==c(2,4,6,10,13,17,21))

      

But it gives me corrupted data and many missing lines. On the other hand, when I use:

q10best <- filter(quest,Team==2 | Team==4 | Team==6 | Team==10 | Team==13 | Team==17 | Team==21)

      

This gives me the correct dataset that I want. What is the difference? what am I doing wrong in the first command? thank

+3


source to share


1 answer


==

checks if two objects are the same. You are trying to check if one object (each item quest$Team

) belongs to a list of values. The correct way to do this is to use%in%



q10best <- filter(quest,Team %in% c(2,4,6,10,13,17,21))

      

+5


source







All Articles