Skip to content
Prev 360366 / 398503 Next

subset by multiple letters condition

Thanks Jean, Does anyone know how to set these [hast1] and [hast2] as the colors of a plot?
On Friday, April 22, 2016 7:39 AM, "Adams, Jean" <jvadams at usgs.gov> wrote:
You can use the grepl() function to give you logicals for each criterion, then combine them as needed.  For example:

# example version of Command
Command <- paste0("_localize_", c("PD","t2","t1_seq", "abc", "xyz", "PD_t1"))

hasPD <- grepl("PD", Command, fixed=TRUE)
hast1 <- grepl("t1", Command, fixed=TRUE)
hast2 <- grepl("t2", Command, fixed=TRUE)
[1] "_localize_t1_seq" "_localize_PD_t1"
[1] "_localize_PD"    "_localize_PD_t1"
[1] "_localize_PD_t1"

Jean
On Fri, Apr 22, 2016 at 8:42 AM, ch.elahe via R-help <r-help at r-project.org> wrote: