[R] how to use substring match as condition?

john seers (IFR) john.seers at bbsrc.ac.uk
Thu May 29 12:53:32 CEST 2008


 

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.



More information about the R-help mailing list