One of those embarrassing Doh! moments to share with the world.

I was trying to subset some data using grepl, but wanted to do a negated search. So any column not beginning with “08” (they all began with “0” something).

Which you can do with:

grepl("0(?!8)",Dataset$Some.Column, perl=T) (negative lookahead) or grepl("^0[^8]",Dataset$Some.Column, perl=T) (negated character class)

But, because grepl is returning a vector of “Yays” or “Nays” there is a much, much simpler approach. Just do:

!(grepl("^08",Dataset$Some.Column))

Doh!