Skip to content
Prev 360335 / 398503 Next

subset by multiple letters condition

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: