Filter a column which contains several keywords

前端 未结 5 1282
Happy的楠姐
Happy的楠姐 2020-12-12 01:53

I am trying to filter a column which contains several keywords (in this example dog and cat) but I am having problems as only the first element is being used.



        
5条回答
  •  忘掉有多难
    2020-12-12 02:32

    grep can use | as an or, so why not paste your filters together with | as a separator:

    dfilter <- df1[grep(paste0(filter1, collapse = "|"), df1$type),]
    

提交回复
热议问题