I have a dataset stored as a data.table DT that looks like this:
print(DT)
category industry
1: administration admin
2: nurse
Data.table is good at grouped operations; I think that's how it can help, assuming you have many rows with the same industry:
DT[ DT[, .I[grep(industry, category)], by = industry]$V1 ]
This uses the current idiom for subsetting by group, thanks to @eddi .
Comments. These might help further:
If you have many rows with the same industry-category combo, try by=.(industry,category).
Try something else in the place of grep (like the options in Ken and Richard's answers).