I have the following vector:
a <- c("abc_lvl1", "def_lvl2")
I basically want to split into two vectors:
("abc", "def")
and ("lvl1", "lvl2)
. I know how to substitute with sub:
sub(".*_", "", a)
[1] "lvl1" "lvl2"
I think this translates into "Search for any number of any characters before "_" and replace with nothing." Accordingly - i thought - this should give me the other desired vector:
sub("_*.", "", a)
, but it removes just the leading character:
[1] "bc_lvl1" "ef_lvl2"
Where do i mess up? This is essentially the equivalent for the "text-to-columns"-function in excel.