title: Filtering a column of (business) names and conditionally remove row if not unique
body: <p>I have business names I web scraped from various sources. Some sites were not precise and dropped the "Inc.", "Inc", "Incorporated", "LTD", "LLC", etc.. Supposing I only have Names, I just want to boil down the list to a manageable amount so I can eyeball it from there and make adjustments. My real data is 18,000 elements, so, removing the incorrect ones like Names[,-c(1,2342,17232)] is impractical. </p>
  
  <p>Here is the example:</p>
  
  <pre><code>Names = c("ABC Services",                   #drop
            "ABC Services, Inc.",             
            "ABC Systems",                    #drop
            "ABC Systems Co.",                  
            "ABC Systems Incorporated",         
            "x Engineering, Inc.",                   
            "x Engineering Incorporated",     #drop     
            "x Green Energy Systems Inc.",           
            "XYZ &amp; Electric",                    
            "XYZ Development, Northwest, LLC",   
            "XYZ Enterprises",                #drop   
            "XYZ Enterprises Inc",               
            "XYZ Generation",                    
            "XYZ Systems",                    #drop 
            "XYZ Systems, Inc",          
            "XYZ Systems, LLC"     
  )
  #count the number of words
  WordCount = sapply(strsplit(Names, " "), length);  
  
  #subtract the first element, put NA at end to retain length
  WordCountMinusFirstElement=c(WordCount[-1],NA);    
  
  #check consecutive modulo x_n+1 %% x_n, to remove pattern of non-increasing word pattern 
      #this just presents a vectorizable way to remove consecutive AND unique names
  Consecutive = WordCountMinusFirstElement %% WordCount;    
  
  df=data.frame(Names,WordCount,WordCountMinusFirstElement,Consecutive);
      "dimensions:";dim(df)
  
  #as a principle I ought to keep my last row since my trick doesn't work here.
  last = df[nrow(df),]
  df = rbind.data.frame( df[which(!(df$Consecutive==0)),],last);
      "dimensions:";dim(df)
  </code></pre>
  
  <p>Frequent patterns: first n characters, "Inc." vs ", Incorporated", etc. I can't drop the "Inc.", "Inc", "Incorporated", "LTD", "LLC", "Co.", etc., because I'll need them, so it seems I'm stuck with looking at the word counts.</p>
  
  <p>The "<em>smartest thing</em>" I can think to do is NOT consider unique and consecutive words with the modulus operator, for instance, <code>x_{n+1} %% x_{n}=0</code>. </p>
  
  <p>I'd like to know what others think would be an efficient way to move on from here. Would it be best to simply characterize the type of "Incorporated", "LTD", "LLC", "Co.", etc., and remove them from the last word position, at this point, and just go with <code>unique(df$Name)</code> at this point? Is some sort of recursive string search better? Could this be put into dplyr so it's just easy to read? </p>
  
  <p>Thanks!</p>