I have the following data frame
id val
a 1
a 2
a 3
b 4
b 5
c 6
I would like to find a subset of this data frame using a subset of the id's. I know I can do the following if the subset criteria is just 1 value for e.g.
y = subset(x,id=='a')
However how do I get a subset if I have a set of several ids. For example c('a','b'). Doing
y = subset(x,id==c('a','b'))
does not give me what I want.
Try the %in% operator.
You can subset with logical operators, e.g.
or you can use the
%in%
operator: