How to filter data based on one word of a column value?

前端 未结 1 633
抹茶落季
抹茶落季 2020-12-22 10:23

I have a dataframe that simplified looks like this only it has 2k rows. I\'m wondering if there\'s a way to either extract data or filter data by the values in the LocationI

相关标签:
1条回答
  • 2020-12-22 11:22

    We can do this with tidyverse

    library(dplyr)
    library(stringr)
    df1 %>% 
        filter(str_detect(LocationID, '\\b(River|Creek)\\b'))
    #   LocationID Code
    #1  Alk River  232
    #2 Bala River 4324
    #3 Cake River  432
    #4  Alk Creek 6767
    #5 Cake Creek  766
    
    0 讨论(0)
提交回复
热议问题