0 votes
1 view
in R Programming by (6.5k points)

I would like to split one column into two within at data frame based on a delimiter. For example,



to become

a    b

b    c

within a data frame.


1 Answer

0 votes
by (25.3k points)

To split the columns at a delimiter, you can use the separate function from the tidyr package as depicted in the following example:

df <- data.frame(ID=1:3, Fun=c('a|b','b|c','x|y'))

>  df

  ID Fun

1  1 a|b

2  2 b|c

3  3 x|y



 df %>%


   separate(col =Fun,into= c("foo", "bar"), sep = "\\|")



  ID foo bar

1  1   a   b

2  2   b   c

3  3   x   y

Welcome to Intellipaat Community. Get your technical queries answered by top developers !