R: Select subset of dataframe by non-unique ids
- by amarillion
Suppose I have a dataframe like this one:
df <- data.frame (id = c("a", "b", "a", "c", "e", "d", "e"), n=1:7)
and a vector with ids like this one:
v <- c("a", "b")
How can I select the rows of the dataframe that match the ids in v? I can't use the id column for rownames because they are not unique.