test1 <- data.frame( D= c("gt","gt","gt", "bk", "j","pro", "r","ll", "oo", "r","bk","oo",
"gt", "bk", "j","oo", "j","ll", "oo", "r", "gt", "bk", "j","oo"),
NM = c("jaes","jan ","tommy","joe","eleder","food","drink","elephant","jaes","jan","tommy","joe",
"jaes","jan","drink","elephant","jaes","jelly", "jelly", "ranch","food","drink","jaes","jan "))
test2 <- data.frame(p1= c("jaes","tommy","joe","eleder","food","jelly"),
p2 = c("jelly","joe","NA","NA","A","jelly"),
oi =c(1,2,3,4,5,6))
- I want to create a new column in data frame res_test named "NC" that will consist of 0 or 1 based on the conditions below
- for every name(s) in column "p1" or "p2" check if either of the name(s) exist in column "NM"
- if the names do not exist enter 0 in column "NC" for that party(s)
- for each name(s) from "p1" that exist in "NM" check the corresponding cell from "D" to see if the string "gt" exists
- if the string exist enter a 1 in the "NC" column for that name(s) if not enter 0
Aucun commentaire:
Enregistrer un commentaire