Das ist mein Datasetfunktioniert nicht Arbeit mit "("
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
Ich möchte alle Zeilen extrahieren enthalten (direct)/(none)
und ich schrieb den folgenden Code grep:
output<-df[grep("(direct)/(none)", df$source),]
Aber es ergibt sich ein out mit 0 Beobachtungen, es funktioniert gut mit anderen wie google/cpc
. Was ist falsch? Ist es das Problem mit "("
Dies wird 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))
Sie könnten überhaupt mit 'grep' überspringen, wenn nur für eine direkte Übereinstimmung' df [df $ source == "(direkt)/(none)"] suchen ' – thelatemail
Es ist vielleicht mein Beispiel nicht Clease Ich möchte alle Zeilen, die "(direkt)/(keine)" enthalten. Zum Beispiel, wenn eine Quelle, wenn ein Benutzer ist l, (direkt)/(keine), a, b, c, brauche ich diese auch – MFR