Home > Back-end >  grepl filter in R program
grepl filter in R program

Time:07-24

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

CodePudding user response:

Just use

library(dplyr)

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