I have a data.frame in R, which, for simplicity, has one column that I want to separate. The following sample snipped using tidyr::separate, almost does the job:
tmp2 <- data.frame( varTreatName = c(
"resp_Nadd_belowCanopy", "resp_NPadd_belowCanopy"
, "resp_sd_Nadd_belowCanopy", "resp_sd_NPadd_belowCanopy"))
tmp2 %>% separate(
"varTreatName", c("varName","treatment","canopyPosition")
, extra = "merge")
which yields:
varName treatment canopyPosition
1 resp Nadd belowCanopy
2 resp NPadd belowCanopy
3 resp sd Nadd_belowCanopy
4 resp sd NPadd_belowCanopy
Several instances are merged to one column. Note, however, that in the described case the first instance varName 'resp_sd' contains the same delimiter that is used by delimiting the factors to separate (treatment, and canopyPosition). But the merge occurs only on the last instances.
Hence, in the last line of the example above I expect to extract: 'resp_sd', 'NPadd', 'belowCanopy'.
How can I merge the first instances instead of the last ones in order to separate only the last n instances?