[R] how to use substring match as condition?
Charles C. Berry
cberry at tajo.ucsd.edu
Thu May 29 18:01:19 CEST 2008
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
More information about the R-help
mailing list