title: remove/replace specific words or phrases from character strings - R
body: <p>I looked around both here and elsewhere, I found many similar questions but none which exactly answer mine. I need to clean up naming conventions, specifically replace/remove certain words and phrases from a specific column/variable, not the entire dataset. I am migrating from SPSS to R, I have an example of the code to do this in SPSS below, but I am not sure how to do it in R.  </p>
  
  <p>EG:</p>
  
  <p>"Acadia Parish" --> "Acadia" (removes Parish and space before Parish)</p>
  
  <p>"Fifth District" --> "Fifth" (removes District and space before District)</p>
  
  <p>SPSS syntax:</p>
  
  <p><code>COMPUTE county=REPLACE(county,' Parish','').</code></p>
  
  <p>There are only a few instances of this issue in the column with 32,000 cases, and what needs replacing/removing varies and the cases can repeat (there are dozens of instances of a phrase containing 'Parish'), meaning it's much faster to code what needs to be removed/replaced, it's not as simple or clean as a regular expression to remove all spaces, all characters after a specific word or character, all special characters, etc. And it must include leading spaces.</p>
  
  <p>I have looked at the replace() gsub() and other similar commands in R, but they all involve creating vectors, or it seems like they do. What I'd like is syntax that looks for characters I specify, which can include leading or trailing spaces, and replaces them with something I specify, which can include nothing at all, and if it does not find the specific characters, the case is unchanged. </p>
  
  <p>Yes, I will end up repeating the same syntax many times, it's probably easier to create a vector but if possible I'd like to get the syntax I described, as there are other similar operations I need to do as well.</p>
  
  <p>Thank you for looking. </p>