I have the following
ex <- tribble(
~type,
"a__0",
"ab__10"
)
> ex
type
a__0
ab__10
I would like to separate by "_". The result would be
letter extra
a __0
ab __10
Note the double underscore
but when I use the following
ex %>% separate(type,into=c("letter","extra"),sep = "_")
I get
letter extra
a
ab
Insert a comma before the first underscore and then separate by comma:
ex %>%
mutate(type = sub("_", ",_", type)) %>%
separate(type, into = c("letter", "extra"), sep = ",")
giving:
# A tibble: 2 x 2
letter extra
* <chr> <chr>
1 a __0
2 ab __10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With