-3

I am new to programming and doing some basic analysis in R Environment

I have two data tables 1) DT1 with one column and 500 rows, containing list of countries 2) DT2 with 5 columns X 10000 rows, and in 1 column i have a text

Problem: I want to search in DT2$Text column if any country name appears from DT1. Can someone let me some piece of code for this such that the DT1 countries are searched in DT2$Text column for whole of DT2?

Thanks all in advance.

  • 2
    Please provide [a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Emmanuel-Lin Dec 05 '17 at 10:05
  • 1
    Also check this will help you solve your problem: [Test if characters in string in R](https://stackoverflow.com/questions/10128617/test-if-characters-in-string-in-r) – Emmanuel-Lin Dec 05 '17 at 10:06
  • 1
    Use `dput` to provide reproducible example. – HNSKD Dec 05 '17 at 10:22

1 Answers1

0
DT1[,appear := lapply(.SD,function(x){any(grepl(x,DT2$Text))}),.SDcols = yourcolumninDT1]

should help you. If you want a proper answer you should give a reproducible example

denis
  • 5,580
  • 1
  • 13
  • 40