title: Split string in data frame into two columns
body: <p>In R I've converted a DocumentTermMatrix with an ngram of 4 into a dataframe and now I want to split the ngram into two columns, one with the first 3 words of the string, the other with the last word.  I can accomplish this through multiple steps, however given the size of the df I was hoping to get it accomplished in on line.</p>
  
  <p>Here's what I'm trying to accomplish:</p>
  
  <pre><code>#             str_name           w123   w4 freq
  # 1 One Two Three Four One Two Three  Four   10        
  </code></pre>
  
  <p>This gives me the first three words:</p>
  
  <pre><code>df &lt;- data.frame(str_name = "One Two Three Four", freq = 10)
  df %&gt;% separate(str_name, c("w123","w4"), sep = "\\w+$", remove=FALSE)
  
  #             str_name           w123 w4 freq
  # 1 One Two Three Four One Two Three       10
  </code></pre>
  
  <p>This gives me the last word but also contains a space:</p>
  
  <pre><code>df &lt;- data.frame(str_name = "One Two Three Four", freq = 10)
  df %&gt;% separate(str_name, c("sp","w4"), sep = "\\w+\\s\\w+\\s\\w+", remove=FALSE)
  
  #             str_name sp    w4 freq
  # 1 One Two Three Four     Four   10
  </code></pre>
  
  <p>This is the long way</p>
  
  <pre><code>df &lt;- data.frame(w4 = "One Two Three Four", freq = 10)
  df &lt;- df %&gt;% separate(w4, c('w1', 'w2', 'w3', 'w4'), " ")
  df$lookup &lt;- paste(df$w1,df$w2,df$w3)
  
  #      w1    w2    w3       w4 freq        lookup
  # 1   One   Two Three     Four   10 One Two Three
  </code></pre>