mercredi 8 mai 2019

R code equivalent to: "if x is part of the data.frame y", then return z"

I am new to R, and I had no clue how I could google this, hence I am asking here. Any help will be appreciated!

I am wondering how I can transform:

If {x (a character) is part of the data.frame y, then return A} else {return B}

That "if x is part of the data.frame" part is the one that I am struggling with. Since x is not a number, I did not know how to write that as a code in R! If it was a number, then it would be something like:

ifelse(sum(x[i] == y[1:12]) == 1, A, B)

How can i do this with a character?

Thank you

Aucun commentaire:

Enregistrer un commentaire