title: Find Match of two data frames and rewrite the answer as data frame
body: <p>i have two data frames which are cleaned and merged as a single csv file , the data frames are like this </p>
  
  <pre><code>  **Source                         Master**
  
   chang chun petrochemical      CHANG CHUN GROUP
   chang chun plastics           CHURCH AND DWIGHT CO INC
   church  dwight                CITRIX SYSTEMS ASIA PACIFIC P L
   citrix systems  pacific       CNH INDUSTRIAL N.V
  </code></pre>
  
  <p>now from these , i have to consider the first name and check with each name of master names and find a match that is relevant and print the output as another data frame. the above data frames are few , but i am working with 20k values as such.</p>
  
  <p>My output must look like this</p>
  
  <pre><code> **Source                         Master                         Result**
  
   chang chun petrochemical      CHANG CHUN GROUP                 CHANG CHUN GROUP
   chang chun plastics           CHURCH AND DWIGHT CO INC         CHANG CHUN GROUP
   church  dwight                CITRIX SYSTEMS ASIA PACIFIC P L  CHURCH AND DWIGHT CO INC
   citrix systems  pacific       CNH INDUSTRIAL N.V               CITRIX SYSTEMS ASIA PACIFIC P L
  </code></pre>
  
  <p>I tried this with possible ways with this link <a href="https://stackoverflow.com/questions/7120312/merging-through-fuzzy-matching-of-variables-in-r">Merging through fuzzy matching of variables in R</a> but , no luck so far..!</p>
  
  <p>Thank in advance!! </p>
  
  <p>when i use the above code for large set of data , the result is this-</p>
  
  <p><strong>code used:</strong></p>
  
  <pre><code>Mast &lt;- pmatch(Names$I_sender_O_Receiver_Customer, Master.Names$MOD, nomatch=NA)
  </code></pre>
  
  <p><strong>OUTPUT</strong></p>
  
  <pre><code>NA NA  2  3 NA NA NA  6 NA NA  9 NA NA NA 12 NA NA NA 13 14 15 16 NA 18 19 20 21 22 NA 24 NA 26 NA 28 NA NA NA 30 NA NA 33 NA 35 36 37 NA 39 40 NA NA 43 NA 45 46 NA 48 49 50 51 52 53 54 55 56 57 58 NA
   [68] 60 61 62 NA NA NA NA 64 NA 66 67 68 69 70 71 72 73 NA 75 76 77 78 NA 79 80 81 NA 83 84 85 86 87 88
  </code></pre>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>Mast &lt;- sapply(Names$I_sender_O_Receiver_Customer, function(x) {
     agrep(x, Master.Names$MOD,value=TRUE) })
  </code></pre>
  
  <p><strong>OUTPUT:</strong></p>
  
  <pre><code>[[1]]
  character(0)
  
  [[2]]
  character(0)
  
  [[3]]
  [1] " CHURCH AND DWIGHT CO INC"
  
  [[4]]
  [1] " CITRIX SYSTEMS ASIA PACIFIC P L"
  
  [[5]]
  character(0)
  </code></pre>
  
  <p>and even with for loop no result is produced.</p>
  
  <p><strong>code:</strong></p>
  
  <pre><code>for(i in seq_len(nrow(df$ICIS_Cust_Names)))
    {
      df$reslt[i] &lt;- grep(x = str_split(df$ICIS_Cust_Names[i]," ")[[1]][1], df$Master_Names[i],value=TRUE)
    }
    print(df$reslt)
  </code></pre>
  
  <p><strong>Code 2:</strong>   <em>Used for loop just for 100 rows</em> </p>
  
  <pre><code>for (i in 100){
    gr1$x[i] = agrep(gr1$ICIS_Cust_Names[i], gr2$Master_Names, value = TRUE, max = list(del = 0.2, ins = 0.3, sub = 0.4))
    gr2$Y[i] = agrep(gr1$ICIS_Cust_Names[i], gr2$Master_Names, value = FALSE, max = list(del = 0.2, ins = 0.3, sub = 0.4))
  }
  </code></pre>
  
  <p><strong>Result:</strong></p>
  
  <pre><code>NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>Error in `$&lt;-.data.frame`(`*tmp*`, "x", value = c(NA, NA, " church  dwight  " : 
    replacement has 3 rows, data has 100
  </code></pre>
  
  <p><strong><em>when observed the result for above is considered , as it checks directly with the row value of each data frames , but i want it to consider first element of Source and check with all the elements of master and come up with a match , likewise for rest.</em></strong> I would appreciate if someone could correct my code ! thanks in advance..! </p>