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. When I try that, I get:
rownames(df) <- df[["id"]]
Error in `row.names<-.data.frame`(`*tmp*`, value = c(1L, 2L, 1L, 3L, 5L, :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘a’, ‘e’