我正在尝试使用combn函数进行不同的组合,然后尝试从每种组合中创建许多txt文件。 我的spt1文件:
spt1 <- split(mydf, mydf[c(,6)]
BSJI BSJI_04204 Basenji Breed Breed 0
BSJI BSJI_04207 Basenji Breed Breed 0
BSJI BSJI_04208 Basenji Breed Breed 1
BSJI BSJI_04212 Basenji Breed Breed 1
BSJI BSJI_04229 Basenji Breed Breed 1
BSJI BSJI_12694 Basenji Breed Breed 2
BSJI_2634 BSJI_2634 Basenji Breed Breed 2
BSJI_34177 BSJI_34177 Basenji Breed Breed 2
BSJI_3454 BSJI_3454 Basenji Breed Breed 2
BSJI_35551 BSJI_35551 Basenji Breed Breed 2
BSJI_35552 BSJI_35552 Basenji Breed Breed 2
但是,当我检查第一个组合时,组合中有2个元素。但是我希望这两个元素在我的输出txt文件中具有不同的长度。
我的文件有6列和7000行。我正在使用combn函数进行多种组合。
combos = as.data.frame(combn(spt1, 2)).
所以我有2个对象和486个变量。
my output.txt
[[1]]
Column1 Column2 Column3 Column4 Column5 Column6
1 BSJI BSJI_04204 Basenji Breed Breed 0
2 BSJI BSJI_04207 Basenji Breed Breed 0
[[2]]
Column1 Column2 Column3 Column4 Column5 Column6
3 BSJI_2634 BSJI_2634 Basenji Breed Breed 2
4 BSJI_34177 BSJI_34177 Basenji Breed Breed 2
5 BSJI_3454 BSJI_3454 Basenji Breed Breed 2
6 BSJI_35551 BSJI_35551 Basenji Breed Breed 2
7 BSJI_35552 BSJI_35552 Basenji Breed Breed 2
I try to make a txt file by
sink("output.txt")
print(combos[, 1])
sink()
但是,输出文件仍然包含[[1]]和[[2]]
the expected output should be like
Column1 Column2 Column3 Column4 Column5 Column6
1 BSJI BSJI_04204 Basenji Breed Breed 0
2 BSJI BSJI_04207 Basenji Breed Breed 0
3 BSJI_2634 BSJI_2634 Basenji Breed Breed 2
4 BSJI_34177 BSJI_34177 Basenji Breed Breed 2
5 BSJI_3454 BSJI_3454 Basenji Breed Breed 2
6 BSJI_35551 BSJI_35551 Basenji Breed Breed 2
7 BSJI_35552 BSJI_35552 Basenji Breed Breed 2
如何将这两个元素按R组合在数据帧列表中并写入txt文件。您有什么建议吗,或者我应该使用其他程序来处理此程序,例如Perl?
I also try to use
write.table(combos[, 1], file = "test.txt", quote=F, row.names=F, col.names=T)
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 77, 91
a part of my data structure of combos
$ X34 :List of 2
..$ :'data.frame': 91 obs. of 6 variables:
.. ..$ FID : Factor w/ 5617 levels "0","10","1023320",..: 505 505 505 505 505 506 507 508 509 510 ...
.. ..$ SID : Factor w/ 7054 levels "10","100","1003",..: 800 801 802 803 804 805 806 807 808 809 ...
.. ..$ Breed : Factor w/ 241 levels "Afghan Hound",..: 24 24 24 24 24 24 24 24 24 24 ...
.. ..$ GroupI : Factor w/ 3 levels "Breed","Mastiff",..: 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ GroupII: Factor w/ 3 levels "Breed","Mastiff",..: 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ Clade : Factor w/ 29 levels "0","Alpine","American Terrier",..: 2 2 2 2 2 2 2 2 2 2 ...
..$ :'data.frame': 172 obs. of 6 variables:
.. ..$ FID : Factor w/ 5617 levels "0","10","1023320",..: 628 628 628 628 783 784 785 786 787 788 ...
.. ..$ SID : Factor w/ 7054 levels "10","100","1003",..: 974 975 976 977 1262 1263 1264 1265 1266 1267 ...
.. ..$ Breed : Factor w/ 241 levels "Afghan Hound",..: 26 26 26 26 72 72 72 72 72 72 ...
.. ..$ GroupI : Factor w/ 3 levels "Breed","Mastiff",..: 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ GroupII: Factor w/ 3 levels "Breed","Mastiff",..: 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ Clade : Factor w/ 29 levels "0","Alpine","American Terrier",..: 8 8 8 8 8 8 8 8 8 8 ...