【发布时间】:2019-12-05 13:57:01
【问题描述】:
我有一个这样的数据框:
Column_A Column_Text
A hello world
A hi world
B go r
C dplyr
另外,我有一个列表,有字符串模式
String_Patterns = c('world', 'go')
我想保留 Column_Text 包含“String_Patterns”模式的行。
我在 stackoverflow 上找到了一些解决方案,但它们并不完全是我想要的:
> grepl("world", df$Column_Text, fixed = FALSE)
# This will lead to TRUE/FALSE (not a subset), and I can only add a pattern one-by-one, for example:
> grepl(c("world", "go"), df$COlumn_Text, fixed = FALSE) # is not working...
期望的输出:
Column_A Column_Text
A hello world #contains pattern world
A hi world #contains pattern world
B go r #contains pattern go
非常感谢!
【问题讨论】: