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

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值