2017-07-26 3 views

Antwort

1

Try this:

mapply(function(x,y) sum(x %in% y), 
    strsplit(df$V1,",", fixed=TRUE),strsplit(df$V2,",", fixed=TRUE)) 
#[1] 1 2 3 

Daten

df<-structure(list(V1 = c("a,b,c", "c,d", "a,b,d"), V2 = c("x,y,z,w,t,a", 
"d,z,c,t", "a,f,t,b,d")), .Names = c("V1", "V2"), row.names = c(NA, 
-3L), class = "data.frame") 
+0

dank @nicola. Kannst du mir bitte einen Weg vorschlagen, die% -Zählung auch zu finden? dh V1 | V2 | Count |% ------ + ------------ + ------- + a, b, c | x, y, z, w, t, a | 1 | 33.33 c, d | d, z, c, t | 2 | 100 a, b, d | a, f, t, b, d | 3 | 100 – aman

+0

haben es geschafft. Vielen Dank :) – aman

Verwandte Themen