How to create a regular expression for a subset of data based on some search strings?

I am trying to find rows for a subset of a data frame. My df looks like this:

dput(df)
structure(list(Cause = structure(c(2L, 1L), .Label = c("jasper not able to read the property table after the release", 
"More than 7000  messages loaded which stuck up"), class = "factor"), 
    Resolution = structure(1:2, .Label = c("jobs and reports are processed", 
    "Updated the property table which resolved the issue."), class = "factor")), .Names = c("Cause", 
"Resolution"), class = "data.frame", row.names = c(NA, -2L))

I am trying to do this:

df1<-subset(df, grepl("*MQ*|*queue*|*Queue*", df$Cause))

search for an MQ or queue or queue in the Cause column, a subset of the df data frame with matched entries. It doesn't seem to work, it catches other entries that the MQ, queue or Queue lines are missing.

Is this the way you do it, any other ideas that I can implement?

+4
source share
2 answers

Regexp seems to work below. I added a line to yours data.frameso that this is a more interesting example.

, * , ​​ |, .

df <- data.frame(Cause=c("jasper not able to read the property table after the release", 
                         "More than 7000  messages loaded which stuck up",
                         "blabla Queue blabla"),
                 Resolution = c("jobs and reports are processed", 
                                "Updated the property table which resolved the issue.",
                                "hop"))

> head(df)
Cause                                           Resolution
1 jasper not able to read the property table after the release                       jobs and reports are processed
2               More than 7000  messages loaded which stuck up Updated the property table which resolved the issue.
3                                          blabla Queue blabla                                                  hop

> subset(df, grepl("(MQ)|(queue)|(Queue)", df$Cause))
Cause Resolution
3 blabla Queue blabla        hop

, ?

+6

:

subset(df, grepl("MQ|Queue|queue", Cause))

, :

subset(df, grepl("mq|queue", Cause, ignore.case = TRUE))

, ?regex ?grepl R.

+1

All Articles