Re: [R] how to pass multiple pattern varibles to grep()

2016-09-23 Thread Bert Gunter
"The | symbol has a completely different meaning in R syntax than it has in regular expression syntax." Well, actually it doesn't -- loosely speaking, they both mean "or" (ok -- interpreting concatenation as "or" is a bit of a stretch). Perhaps to clarify your statement (stop here if none is

Re: [R] how to pass multiple pattern varibles to grep()

2016-09-23 Thread Jeff Newmiller
The | symbol has a completely different meaning in R syntax than it has in regular expression syntax. R hands of pattern strings to the regex library without looking inside the strings any more than it has to. Likewise, the regex library has no clue about R syntax. Your attempt failed to create

[R] how to pass multiple pattern varibles to grep()

2016-09-23 Thread Fix Ace via R-help
Hello, there, My patterns are defined by variables, for example:z="h"v="x" I have a vector: a=c("th","mx","t") I would like to find elements in vector a that contain either "h", or "x" grep("h|x", a) apparently works. However, when I tried: grep(z|v,a), it did not work. Can anyone help how to