l <- c("a","b","c")
m is a 5×2 data frame. C1 is 1:5, C2 is a:e:
m <- data.frame(C1 = 1:5, C2 = letters[1:5], stringsAsFactors = FALSE)
I want to find n, where it contains only those rows of m where m$C2 is in the values stated in l
The resulting n is a 3×2 such that C2 is a:c, i.e.
C1 C2
1 1 a
2 2 b
3 3 c
One option is to do the matching by hand with
%in%:Or alternatively via the
match()function:where the
nomatchargument is required to get rid of theNArows.