Deleting specific rows from a data frame

后端 未结 3 1993
北荒
北荒 2020-12-03 12:49

I am working with some US govt data which has a lengthy list of cities and zip codes. After some work, the data is in the following format.

dat1 = data.frame         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-03 13:20

    I think two grepl expressions should do the trick:

    > dat2[ !( grepl("City", dat2$tag) &  grepl("^\\d", dat2$keyword) ) , ]
                 keyword              tag
    1             Bremen       AlabamCity
    2              Brent       AlabamCity
    4        Chelsea, AL    AlabamaCityST
    5 Bailytown, Alabama AlabamaCityState
    7              54023   AlabamaZipCode
    8              54024   AlabamaZipCode
    

    You are eliminating the rows where there are digits in keyword and "City" in tag

提交回复
热议问题