Say I have a csv file containing this sort of data from the
df <- data.frame(x = c("a.b", "a.d", "b.c")) df %>% separate(x, c("A", "B")) A B 1 a b 2 a d 3 b c
This works great if you know how many columns will be in your output. In my case, I'm connecting this dataset to a
shinydashboard that dynamically generates a plot based on this data.
I'd like to separate the column
x into different columns by a separator
. and dynamically generate custom column names along the way. Something I had in mind:
df %>% separate(col = x, into = paste0("x_", 1:2)) x_1 x_2 1 a b 2 a d 3 b c
but I'd like the numbers coming after
_ to be reactively generated depending on the number of columns
x is separated into.