I want to return a logical vector for regexp matches over a character vector, but match or %in do not seem to support regular expressions, e.g.:
> x <- c("Bill", "Brett", "Jane")
> grep("^B", x)
[1] 1 2
> x %in% "^B"
[1] FALSE FALSE FALSE
I would like this to return
[1] TRUE TRUE FALSE
Ideas?
Thanks,
Roberto
Just chain it:
So you could write yourself a little helper function that does both as shown here. But I presume one of the
grep()variants does that as well… Ah, yes,grepl()is your friend:Nothing that a quick
help(grep)can’t cure 😉