I would like to filter a data frame by checking to see if a column starts with a number that is also stored in a numeric vector.
For example, consider the below data frame, with columns Commentand Comment.Id:
Comment | Comment.Id
This comment | 34_1_1_1
That comment | 24
Another comment | 54_1_1
Please comment | 234
More comments | 13_1_1
Many comments | 12
Comment again | 119_1_1
And the following vector num:
num <- c(34, 54, 234, 13, 119)
I would like to look through the Comment.Id column, and if a comment Id starts with a number that is contained in the num vector, then filter for that row.
The resulting data frame would look like this:
Comment | Comment.Id
This comment | 34_1_1_1
Another comment | 54_1_1
Please comment | 234
More comments | 13_1_1
Comment again | 119_1_1
I am using the R language.