title: Splitting a character column by pattern matching
body: <pre><code>                                       Province                   ElecDistName                               Candidate Votes Majority  Vper MajPer
                                            &lt;chr&gt;                          &lt;chr&gt;                                   &lt;chr&gt; &lt;int&gt;    &lt;int&gt; &lt;dbl&gt;  &lt;dbl&gt;
  1 Newfoundland and Labrador/Terre-Neuve-et-Labrador St. John's East/St. John's-Est                     Nick Whalen Liberal 20974      646  46.7    1.4
  2 Newfoundland and Labrador/Terre-Neuve-et-Labrador St. John's East/St. John's-Est Jack Harris ** NDP-New Democratic Party 20328       NA  45.3     NA
  3 Newfoundland and Labrador/Terre-Neuve-et-Labrador St. John's East/St. John's-Est           Deanne Stapleton Conservative  2938       NA   6.5     NA
  4 Newfoundland and Labrador/Terre-Neuve-et-Labrador St. John's East/St. John's-Est        David Anthony Peters Green Party   500       NA   1.1     NA
  5 Newfoundland and Labrador/Terre-Neuve-et-Labrador St. John's East/St. John's-Est                   Sean Burton Communist   140       NA   0.3     NA
  6                   New Brunswick/Nouveau-Brunswick                    Fundy Royal                 Alaina Lockhart Liberal 19136     1775  40.9    3.8
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/MYFFb.jpg" rel="nofollow noreferrer">Top of Dataset</a></p>
  
  <p>Amateur question here, I'm trying to split the Candidate column into two, one containing the name, the other containing the party. I've tried some of the separate functions posted on here:</p>
  
  <pre><code>separate(ElecResults, Candidate, into = c("Name", "Party"), sep = " (?=[^ ]+$)")
  </code></pre>
  
  <p>But this seems to miss a lot of observations. For the Candidates with three names, the problem is obvious, but there are others that it just seems to miss entirely (the candidates with the inexplicable double asterisks for one).</p>
  
  <p>I have tried to think of if functions combined with grepl where it would identify the most common party names, such as Liberal, Conservative, NDP and Green, and create a new column called Party with the party name in it, but continuously get error messages everytime I try.</p>
  
  <p>If anyone has an idea for how I can split this column it would be a huge help.</p>
  
  <p>Thank you! </p>
  
  <p>Here is the code using dput: </p>
  
  <pre><code>structure(list(Province = c("Newfoundland and Labrador/Terre-Neuve-et-Labrador", 
  "Newfoundland and Labrador/Terre-Neuve-et-Labrador", "Newfoundland and Labrador/Terre-Neuve-et-Labrador", 
  "Newfoundland and Labrador/Terre-Neuve-et-Labrador", "Newfoundland and Labrador/Terre-Neuve-et-Labrador", 
  "New Brunswick/Nouveau-Brunswick"), ElecDistName = c("St. John's East/St. John's-Est", 
  "St. John's East/St. John's-Est", "St. John's East/St. John's-Est", 
  "St. John's East/St. John's-Est", "St. John's East/St. John's-Est", 
  "Fundy Royal"), Candidate = c("Nick Whalen Liberal", "Jack Harris ** NDP-New Democratic Party", 
  "Deanne Stapleton Conservative", "David Anthony Peters Green Party", 
  "Sean Burton Communist", "Alaina Lockhart Liberal"), Votes = c(20974L, 
  20328L, 2938L, 500L, 140L, 19136L), Majority = c(646L, NA, NA, 
  NA, NA, 1775L), Vper = c(46.7, 45.3, 6.5, 1.1, 0.3, 40.9), MajPer = c(1.4, 
  NA, NA, NA, NA, 3.8)), .Names = c("Province", "ElecDistName", 
  "Candidate", "Votes", "Majority", "Vper", "MajPer"), row.names = c(NA, 
  -6L), class = c("tbl_df", "tbl", "data.frame"))
  </code></pre>