这是我的数据集不grep的使用功能工作“(”
userId source transactions
(dbl) (chr) (chr)
1 1 google/cpc, google/cpc 0, 1
2 2 (direct)/(none) 0
3 3 (direct)/(none) 1
4 4 google/organic, (direct)/(none) 0
5 5 google/organic 0
6 6 google/organic 0
我想提取所有的行包含(direct)/(none)
,我写了下面的代码:
output<-df[grep("(direct)/(none)", df$source),]
但是它的输出结果为0,与其他产品如google/cpc
有什么不同?这是否是“(”?
这dput
dput(df)
structure(list(userId = c(1, 2, 3,
4, 5, 6, 7, 8,
9, 10), source = c("google/cpc, google/cpc",
"(direct)/(none)", "(direct)/(none)", "google/organic",
"google/organic", "google/organic", "(direct)/(none)",
"google/cpc, google/cpc, google/cpc, google/organic, google/cpc",
"(direct)/(none)", "(direct)/(none)"), transactions = c("0, 1",
"0", "1", "0", "0", "0", "0", "0, 0, 0, 0, 0", "0", "1")), .Names = c("userId",
"source", "transactions"), class = c("tbl_df", "data.frame"
), row.names = c(NA, -10L))
你可以使用'grep'跳过所有,如果只是寻找一个直接匹配'DF [DF $源==“(直接)/(无)”]' – thelatemail
对不起也许我的例子不是易洁我想要所有包含“(直接)/(无)”的行。例如,如果一个用户的源是l,(直接)/(无),a,b,c,我也需要这个 – MFR