Subset a data frame using OR when the column contains a factor Subset a data frame using OR when the column contains a factor r r

Subset a data frame using OR when the column contains a factor


You need fake.trunk <- fake[fake$nm == "a" | fake$nm == "b", ]. A more concise way of writing that (especially with more than two conditions) is:

fake[ fake$nm %in% c("a","b"), ]


Another approach would be to use subset() and write

fake.trunk = subset(fake, nm %in% c('a', 'b'))