J'ai deux dataframes:valeur de retour non-correspondance comme-utilise qdaptools (recherche)
state = c("CA","WA","OR","AZ")
first = c("Jim","Mick","Paul","Ron")
df1 <- data.frame(first, state)
df1
first state
1 Jim CA
2 Mick WA
3 Paul OR
4 Ron AZ
newstate = c("TX", "LA")
first =c("Jim","Mick")
df2 <- data.frame(first,newstate)
df2
first newstate
1 Jim TX
2 Mick LA
Et je suis en utilisant la fonction qdaptools
de recherche:
library(qdaptools)
df1$match <- lookup(df1$first, df2[, 1:2])
> df1
first state match
1 Jim CA TX
2 Mick WA LA
3 Paul OR <NA>
4 Ron AZ <NA>
Est-il possible d'ignorer nomatch ou avez nomatch renvoie la variable existante tel quel? Ce serait un exemple de résultat souhaité:
first state match
1 Jim CA TX
2 Mick WA LA
3 Paul OR OR
4 Ron AZ AZ