- 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
- 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
- > test$f <- NULL
- > test$m <- NULL
- > re <- strsplit(as.character(test$pedigree),"_X_")
- > for(i in 1:dim(test)[2]) {test$f[i] <- re[[i]][1];test$m[i] <- re[[i]][2]}
- > test
- type id pedigree trait1 trait2 trait3 f m
- 1 training L0001 f1_X_m1 -1.746103 -0.7855251 -0.331637 f1 m1
- 2 training L0002 f2_X_m1 -1.679248 -1.5694899 -2.572614 f2 m1
- 3 training L0003 f3_X_m1 -2.748920 -0.6086439 -1.108812 f3 m1
- 4 training L0004 f4_X_m1 -2.414647 -0.6720451 -1.315051 f4 m1
- 5 training L0005 f5_X_m1 -1.879812 -0.7409128 -1.879181 f5 m1
- 6 training L0006 f6_X_m1 -2.347793 -0.4017722 -1.442920 f6 m1
我的处理思路,将test$pedigree提取出来,变成字符串,然后用strsplit分割,然后复制数据框test新的列:f和m。
代码写的比较复杂,水平有限!!
我想问,有没有简单的处理方法?
十分感谢。


雷达卡





京公网安备 11010802022788号







