使用 : 和 - 符号将列拆分为 R 中的多列

Split column with : and - symbols into multiple columns in R

我有如下数据:

SAMPLE  TYPE    INTERVAL    KB  CHR MID_BP  TARGETS NUM_TARG    Q_EXACT Q_SOME  Q_NON_DIPLOID   Q_START Q_STOP  MEAN_RD MEAN_ORIG_RD
BOBBY   DEL chrX:120065155-120119383    54.23   chrX    120092269   395..428    34  5   92  94  1   10  -1.88   13.13
JOHN    DUP chrX:134872056-134874055    2.00    chrX    134873055   440..442    3   40  54  54  27  19  4.32    105.48
JOHN    DUP chrX:134930172-134965407    35.24   chrX    134947789   447..455    9   6   89  90  6   46  2.76    79.67

我想在 table 内拆分名为 INTERVAL 的第 3 列,按 :- 符号,如下所示:

a    b         c 
chrX 120065155 120119383

我尝试了这个仅由 : 分隔的命令行。如何用两个符号拆分列?

df <- separate(data = df, col = INTERVAL, into = c("a", "b", "c"), sep = "\:")

我可以这样做,但也许有更好的方法:

df$INTERVAL <-  gsub("-", ":", df$INTERVAL)
df <- separate(data = df, col = INTERVAL, into = c("a", "b", "c"), sep = "\:")

使用sep = "\:|\-"

df %>% 
  separate(INTERVAL, into=c("a", "b", "c"), sep = "\:|\-")