Re: [R] how to use substring match as condition?

From: Charles C. Berry <cberry_at_tajo.ucsd.edu>
Date: Thu, 29 May 2008 09:01:19 -0700

On Thu, 29 May 2008, Albert Vilella wrote:

> Hi,
>
> How can I use a substring match as a condition in a subset command?
>

Perhaps

         subset(input, field1=="blah1" & regexpr("blah2",field3) != -1 )

??

Study in

         example(gsub)

the regexpr example

and in

         ?gsub

the 'Value' section as it pertains to regexpr.

HTH, Chuck

> Sth like this:
>
> subset(input, field1=="blah1" & field2=="blah2") # but now with substring
> match in field2
>
> subset(input, field1=="blah1" & field3 *substringmatch* "blah3")
>
> I've tried with gsub, but it won't work:
>
> subset(input, field1=="blah1" & gsub("blah3","",input$field3))
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry_at_tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 29 May 2008 - 17:36:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 29 May 2008 - 18:30:42 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive