library(tidyverse)
Code <- c("a", "b", "c", "d", "e", "f")
Info <- c("test", "shop for test", "test", "shop group for test", "test", "test shop for test")
dd <- data.frame(Code, Info)
rm(Code, Info)
tt <- dd %>%
filter(str_detect(Info, "^shop for | shop group for")) #it should generate two entries
答案 0 :(得分:0)
由于数据中存在清晰的模式,因此可以使用substr
在开头查找单词'shop'
。将其转换为逻辑数据并对数据框进行子集化。
dd[substr(dd[,2], 1, 4)=='shop',]
Code Info
2 b shop for test
4 d shop group for test