R语言中数据框某一列进行分割,变成两列

R语言中数据框某一列进行分割,变成两列

      type    id pedigree    trait1     trait2    trait3
1 training L0001  f1_X_m1 -1.746103 -0.7855251 -0.331637
2 training L0002  f2_X_m1 -1.679248 -1.5694899 -2.572614
3 training L0003  f3_X_m1 -2.748920 -0.6086439 -1.108812
4 training L0004  f4_X_m1 -2.414647 -0.6720451 -1.315051
5 training L0005  f5_X_m1 -1.879812 -0.7409128 -1.879181
6 training L0006  f6_X_m1 -2.347793 -0.4017722 -1.442920

数据框中test的pedigree一列,我想将pedigree用切割符“X”,变成f和m两列

      type    id f m trait1     trait2    trait3
1 training L0001  f1 m1 -1.746103 -0.7855251 -0.331637
2 training L0002  f2 m1 -1.679248 -1.5694899 -2.572614
3 training L0003  f3 m1 -2.748920 -0.6086439 -1.108812
4 training L0004  f4 m1 -2.414647 -0.6720451 -1.315051
5 training L0005  f5 m1 -1.879812 -0.7409128 -1.879181
6 training L0006  f6 m1 -2.347793 -0.4017722 -1.442920
library(tidyverse)
separate(data = test, col = pedigree, into = c("m", "trait1"), sep = "_X_")

https://bbs.pinggu.org/thread-6269428-1-1.html

你可能感兴趣的:(R语言中数据框某一列进行分割,变成两列)