Having two dataframes:
x <- data.frame(numbers=c('1','2','3','4','5','6','7','8','9'), coincidence="NA")
and
y <- data.frame(numbers=c('1','3','10'))
How can I check if the observations in y
(1, 3 and 10) also exist in x
and fill accordingly the column x["coincidence"]
(for example with YES|NO, TRUE|FALSE...).
I would do the same in Excel with a formula combining IFERROR
and VLOOKUP
, but I don't know how to do the same with R.
Note:
I am open to change data.frames to tables or use libraries. The dataframe with the numbers to check (y
) will never have more than 10-20 observations, while the other one (x
) will never have more than 1K observations. Therefore, I could also iterate with an if
, if it´s necessary