I have a data frame like so:
| X | Y
----------
| 8 | 8 13
| 1 | 8 13
| 5 | 8 13
| 13 | 8 13
| 3 | 8 13
| 14 | 7
| 14 |
Col X is in integer format. Col Y is in character format, the numbers are separated by a space. This column can have one number (single or double digit), up to 20 numbers, all separated by a space, or it can be blank.
I wish to match the number in Col X with any of the number in Col Y, like so:
| X | Y | FLAG
---------------
| 8 | 8 13 | Yes <-- 8 is a match
| 1 | 8 13 | No <-- Even though 1 appears in Col Y, it is technically number 13
| 5 | 8 13 | No
| 13 | 8 13 | Yes
| 3 | 8 13 | No <-- Even though 3 appears in Col Y, it is technically number 13
| 14 | 7 | No
| 14 | | No
I tried to unlist the numbers like so:
as.numeric(unlist(str_extract_all(data$colY, "[\\.0-9e-]+")
But this only separates the numbers. How can this be achieved?