BobbyG
BobbyG

Reputation: 45

grepl filter in R program

Trying to filter the rows which contains only the word DEV but the below is pulling wrong matches like SEV HEV and BEV as well

Data

Airport_ID<-c("3001","3002","3003","3004")
    Airport_Name<-c("Adelaide DEV DTSUpdated","Brisbane HEV Land Airport Land ADTS",
                    "Washington SEV INC Airport DTSUpdated","DALLAS Airport BEV INCUpdated")
dfu<-data.frame(Airport_ID,Airport_Name)

Filter Code

Filter_Data <- dfu %>%  
                   dplyr::filter(grepl(" \\DEV\\ ",Airport_Name))

Intended Output:

    3001 Adelaide DEV DTSUpdated

Upvotes: 0

Views: 106

Answers (1)

Mohamed Desouky
Mohamed Desouky

Reputation: 4425

Just use

library(dplyr)

dfu |> filter(grepl("DEV" , Airport_Name , fixed = T))
  • output
  Airport_ID            Airport_Name
1       3001 Adelaide DEV DTSUpdated

Upvotes: 1

Related Questions