library(tidyverse)
df <- expand.grid(group = c("alpha", "beta"),
dimension = c(1, 2),
stringsAsFactors = F) %>%
tbl_df() %>%
mutate(gr_dim = paste0(group, dimension))
# splits the one left most character
df %>%
separate(gr_dim, sep = 1, into = c("gr", "dim"))
# creates two columns, one of which is the original column, the other blank
df %>%
separate(gr_dim, sep = -1, into = c("gr", "dim"))
# splits the two left-most characters
df %>%
separate(gr_dim, sep = 2, into = c("gr", "dim"))
# splits the one right-most character
df %>%
separate(gr_dim, sep = -2, into = c("gr", "dim"))
According to the documentation for the
separgument:However, to split the right-most character into a new column,
sepmust be set to -2. Reproducible example: