[R] string pattern matching
drjimlemon at gmail.com
Wed Mar 22 01:43:10 CET 2017
This may help you:
test <- c("x1", "x2", "x3", "x1 + x2 + x3")
for(i in 1:nbits) if(length(grep(xbits[i],x2))) xans[i]<-TRUE
multigrep("x1 + x3","x1 + x2 + x3")
multigrep("x1 + x4","x1 + x2 + x3")
On Wed, Mar 22, 2017 at 10:50 AM, Joe Ceradini <joeceradini at gmail.com> wrote:
> Hi Folks,
> Is there a way to find "x1 + x2 + x3" given "x1 + x3" as the pattern?
> Or is that a ridiculous question, since I'm trying to find something
> based on a pattern that doesn't exist?
> test <- c("x1", "x2", "x3", "x1 + x2 + x3")
>  "x1" "x2" "x3" "x1 + x2 + x3"
> grep("x1 + x2", test, fixed=TRUE, value = TRUE)
>  "x1 + x2 + x3"
> But what if only have "x1 + x3" as the pattern and still want to
> return "x1 + x2 + x3"?
> grep("x1 + x3", test, fixed=TRUE, value = TRUE)
> I'm sure this looks like an odd question. I'm trying to build a
> function and stuck on this. Rather than dropping the whole function on
> the list, I thought I'd try one piece I needed help with...although I
> suspect that this question itself probably does bode well for my
> function :)
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help