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

From: john seers (IFR) <john.seers_at_bbsrc.ac.uk>
Date: Thu, 29 May 2008 11:53:32 +0100

 

Something like this may be close to what you want:

subset(input, field1=="blah1" & !is.na(charmatch("blah3",input$field3)))  

---

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org]
On Behalf Of Albert Vilella
Sent: 29 May 2008 11:38
To: r-help_at_r-project.org
Subject: [R] how to use substring match as condition?

Hi,

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

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.
______________________________________________
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 - 12:23:05 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 - 12:30:40 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