I have a character vector and a data.tabe:
library(data.table)
pselection <- c("12345" , "2345", "12345678")
dt <- data.table("title"=c("First title", "Second Title", "Third Title", "Fourth Title"),
"sha"=c("12345", "2345; 66543; 33423", "22222; 12345678;", "666662345; 444"))
Now I want to select all rows of the data.table which match the sha column partially based on the ; seperator. So basically I want this output:
title sha
1: First title 12345
2: Second Title 2345; 66543; 33423
3: Third Title 22222; 12345678;
How would I do this?
I tried this:
selected <- dt[sha %in% pselection]
but it only selects exact matches and using the %like% expression is just for matching one expression not many. Concatenating to a regular expression (like paste(pselection, collapse="|")) is out of the question because my pselection is > 10.000.Thanks for the help in advance!