You can use tidyr::separate
and separate after the first position, though your data need to be in a data frame (combination2
):
library(tidyr)
combination2 <- data.frame(combination)
combination2 %>% separate(combination, into = c("sep.1", "sep.2"), sep = 1)
output:
# sep.1 sep.2
# 1 A B
# 2 A C
# 3 A D
# 4 A E
# 5 A F
# 6 A G
# 7 A H
# 8 B C
# 9 B D
# 10 B E
A base R approach would be to use strsplit
and do.call
with rbind
on the original combination
do.call(rbind, strsplit(combination, split = ""))
Output
# [,1] [,2]
# [1,] "A" "B"
# [2,] "A" "C"
# [3,] "A" "D"
# [4,] "A" "E"
# [5,] "A" "F"
# [6,] "A" "G"
# [7,] "A" "H"
# [8,] "B" "C"
# [9,] "B" "D"
# [10,] "B" "E"