title: Separate string after last underscore
body: <p>This is indeed a duplicate for this question 
  <a href="https://stackoverflow.com/questions/32119963/r-split-string-using-tidyrseparate">r-split-string-using-tidyrseparate</a>, but I cannot use the MWE for my purpose, because I do not know how to adjust the regular Expression.
  I basically want the same thing, but split the variable after the last underscore.</p>
  
  <p>Reason: I have data where some columns show up several times for the same factor/type. I figured I can melt the data separate the value variable before the type string and spread it out again to a wide format with less columns. My Problem is that my variable names have different several underscores and I would like to learn how to separate after the last underscore which I added beforehand.</p>
  
  <p>MWE</p>
  
  <pre><code>library(tidyr)
  library(data.table)
  dt&lt;-data.table(Name=c("A","B","C"),Var_1_EVU=c(2,NA,NA),Var_1_BdS=c(NA,3,4),Var_2_BdS=c(NA,3,4))
  dt.long&lt;-melt(dt, id.vars=c("Name"))
  dt.long&lt;-separate(dt.long,variable, c("test","type"), sep='/[^_]*$/')
  dt.wide&lt;-spread(dt.long,key=Name,value=value) 
  </code></pre>
  
  <p>I would like something like</p>
  
  <pre><code>   Name type Var1 Var2
  1:    A  BdS   NA   NA
  2:    A  EVU    2   NA
  3:    B  BdS    3    3
  4:    B  EVU   NA   NA
  5:    C  BdS    4    4
  6:    C  EVU   NA   NA
  </code></pre>