Quantcast
Viewing latest article 28
Browse Latest Browse All 35

analog of setdiff() using regular expressions

Suppose I want to exclude values matching a series of regular expressions from a character vector, in the same way that I would use setdiff() for fixed character strings, e.g.

value <- c("apple pie", "cat", "dog", "dogmatic", "no apples")re_setdiff(value, c("^apple", "^dog"))## desired results:value[c(2,5)][1] "cat"       "no apples"

I know how I can code this by brute force (see my answer) but am wondering if there's a more efficient/more idiomatic way to do it (maybe something in stringi/stringr?), or something that's already in a (widely used) package?


Viewing latest article 28
Browse Latest Browse All 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>