Filter a column which contains several keywords

前端 未结 5 1270
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:17

    Like @Tgsmith61591 mentioned, the pattern argument for the grep function requires a string. Since you're passing in a vector it's warning you that it will only process the first element.

    Another solution would be something like this:

    dfilter <- unique(grep(paste(filter1, collapse = "|"), df1$type, value=TRUE))
    

    See this post grep using a character vector with multiple patterns

提交回复
热议问题