I tried to reproduce your situation using cat, and I hope that this is what you actually have. So let's say this is your file
cat("12 ->3 4 5
14->2 1
1->3 5 6",
file = "test.txt")
Using data.table, I quickly read it, specifying some kind of invalid separator, so the result will be one set of column data
library(data.table)
dt <- fread("test.txt",
sep = ",",
header = FALSE)
The next step is a double split, first dividing the numbers on both sides of the arrow ( ->), and then dividing into a group
dt[, tstrsplit(V1, "\\s*->\\s*", type.convert = TRUE)
][, strsplit(V2, "\\s+"), by = .(indx = V1)]
source
share