I have data that looks like this:
sources
1: Jana’s iPhone
2: Richard's iPhone 6
3: Denise's
4: Sara’s iPhone
5: Jeff’s Apple Watch
6: BLAIR’s Apple Watch
7: Sunshine's iPhone
8: Brian's iPhone
9: Jonathan’s Apple Watch
10: patricia’s Apple Watch
I'm trying to replace any string that contains iPhone just say iPhone. How can I do this?
I tried the following on a data table sources that contains a column also called sources:
sources[length(grep("iPhone", sources)) > 0, sources:= "iPhone"]
But this converts all rows to "iPhone" even if the row did not originally contain a string with "iPhone". I am guessing this is because grep or length is not vectorized, so I end up selecting all rows. So then my question becomes how can I identify the rows that contain a substring?