title: R split text string into last and first elements
body: <p>I'm looking for help how I can split complex names column into 2 columns for first and last names.</p>
  
  <pre><code> df &lt;- data.frame( PREFIX=c("A_B","A_C","A_D","B_A","A_B_C","B_D_E","C_B_A","B_A"),
           VALUE=c(1,2,3,4,5,6,7,8) )
  </code></pre>
  
  <p>The following produces the first part of the task, but I couldn't figure out how to select the last element when I have different pattern for the remaining string </p>
  
  <pre><code> # split PREFIX into new columns
   df$name1 = as.character(lapply(strsplit(as.character(df$PREFIX), split="_"), "[", 1))
  </code></pre>