title: Find partial matching strings between two vectors in R
body: <p>I am working with two string vectors in R. </p>
  
  <p>The first one, <em>proprietor</em>, contains about 100,000 elements and looks like:</p>
  
  <pre><code>&gt; proprietor
   [1] "GERALD RICA LIMITED"                                             
   [2] "EUROMASTER STUDIO SRL"                                           
   [3] "CENTRE D'ECHANGES INTERNATIONAUX (CEI)"                          
   [4] "RONTEC SERVICE STATION 1A LIMITED"                               
   [5] "MOORGARTH PROPERTIES (LUXEMBOURG) S.A.R.L"                       
   [6] "BEAVRON INVESTMENTS LIMITED"                                     
   [7] "MITRALI LIMITED" 
  </code></pre>
  
  <p>The other one, <em>name</em>, contains about 700,000 similar elements :</p>
  
  <pre><code>&gt; name 
   [1] "MULTIPOINT HOLDINGS LIMITED"                                     
   [2] "NYASA PROPERTY LIMITED"                                          
   [3] "WHITE LODGE HOLDINGS LIMITED"                                    
   [4] "MULTIPOINT HOLDINGS LIMITED"                                     
   [5] "MULTIPOINT HOLDINGS LIMITED"                                     
   [6] "JBL INVESTMENT LIMITED"                                          
   [7] "DIMBLEBY LIMITED"                                                
   [8] "LIDL U.K. GMBH"     
  </code></pre>
  
  <p>I would like to know which elements of <em>proprietor</em> are also in <em>name</em>, taking into account that there could be some typos or that some words like "LIMITED" can also be written down "LTD" for example. </p>
  
  <p><strong>What I have already tried:</strong></p>
  
  <ul>
  <li><p><code>proprietor %in% name</code> returns an empty element, which I know is not the case</p></li>
  <li><p><code>intersect(proprietor, name)</code> is not working because there are duplicates in my vectors</p></li>
  <li><p>mainly, I've tried to do a loop with <code>agrep()</code> to allow for partial matches:</p></li>
  </ul>
  
  <pre><code>    for (i in 1:97034) {
        if (is.null(agrep(proprietor[i], name, max.distance=0.1, value=TRUE, useBytes=TRUE, costs=NULL, ignore.case=TRUE))=="TRUE") {
          test[i] &lt;- 1
        } else {
          test[i] &lt;- agrep(proprietor[i], name, max.distance=0.1, value=TRUE, useBytes=TRUE, costs=NULL, ignore.case=TRUE)
        }
      }
  </code></pre>
  
  <p>It returns the error "regcomp error:  'Out of memory'". I am beginning in R so 1) I can see this loop is not the easiest way to do it 2) I didn't get how to correct this out of memory error.</p>
  
  <ul>
  <li>I also tried the solution given in this post: <a href="https://stackoverflow.com/questions/38371321/find-matching-strings-between-two-vectors-in-r">Find matching strings between two vectors in R</a> but I couldn't implement it (error message: Error: assertion 'tree->num_tags == num_tags' failed in executing regexp: file 'tre-compile.c', line 634. I couldn't find where it was coming from.)</li>
  </ul>
  
  <p>Any suggestion on how to solve this problem would be greatly appreciated!</p>