jeudi 30 novembre 2017

If a value exists in data.frame then... (R)

I have two data.frame:

A <- c("name", "city", "code")
B <- c("code", "city")

I would like to see whether each value of A$city exists in B$city and in that case to report the correspondent B$code value in a new column of A. Here is what I've done:

A$code <- ""
found <- is.element(A$city, B$city)

Then, how should I perform the if statement?

Aucun commentaire:

Enregistrer un commentaire