2013-03-08 146 views
1

這裏我的問題在R:ř複製「row.names」不允許

mtable <- read.table(paste(".folder_1362704682.4574","/groups.txt",sep=""),sep="\t",comment.char='',skip=0, header=TRUE, fill=TRUE,check.names=FALSE) 

第一夾部分或糊劑()通常由VAR裹,用於調試目的 - >靜態的。

我總是得到消息:

Error in read.table(paste(".frunc_1362704682.4574", "/groups.txt", sep = ""), : 
    duplicate 'row.names' are not allowed 

但是,如果我看的文件,這個頭:

root_node_name node_name  node_id #genes_in_root_node  #genes_in_node #genes_with_variable=1_in_root_node  #genes_with_variable=1_in_node raw_p_underrepresentation_of_variable=1 raw_p_overrepresentation_  of_variable=1 FWER_underrepresentation  FWER_overrepresentation FDR_underrepresentation FDR_overrepresentation 

我看不到任何重複.. :( 我讀過在另一個討論中,我應該嘗試:

mtable <- read.table(paste(".frunc_1362704682.4574","/groups.txt",sep=""),sep="\t",comment.char='',skip=0, header=TRUE, fill=TRUE,check.names=FALSE,**row.names=NULL**) 

這很好,但之後所有標題向右移一列:

> head(mtable, n=1) 
      row.names       root_node_name node_name 
1 molecular_function trans-hexaprenyltranstransferase activity GO:0000010 
    node_id #genes_in_root_node #genes_in_node 
1 17668     2   2419 
    #genes_with_variable=1_in_root_node #genes_with_variable=1_in_node 
1         0      0.74491 
    raw_p_underrepresentation_of_variable=1 
1          1 
    raw_p_overrepresentation_of_variable=1 FWER_underrepresentation 
1          1      1 
    FWER_overrepresentation FDR_underrepresentation FDR_overrepresentation 
1   

任何想法都可以解決它嗎? :(

編輯:作爲comenteer說,這主要是與THR行的問題..愚蠢的IAM我認爲它的洞察力來自於頭,但我不想命名

好。行,它只是應該容易讀他們... OO不能是硬的,或

文件的內容:

molecular_function  trans-hexaprenyltranstransferase activity  GO:0000010  17668 2  2419 0  0.74491 1  1  1  -1  -1 
molecular_function  single-stranded DNA specific endodeoxyribonuclease activity  GO:0000014  17668 5  2419 0  0.478885  1  1  1  -1  -1 
molecular_function  lactase activity  GO:0000016  17668 1  2419 0  0.863086  1  1  1  -1  -1 
molecular_function  alpha-1,3-mannosyltransferase activity GO:0000033  17668 3  2419 0  0.64291 1  1  1  -1  -1 
molecular_function  tRNA binding GO:0000049  17668 27  2419 7  0.975698  0.0663832  1  1  -1  -1 
molecular_function  fatty-acyl-CoA binding GO:0000062  17668 20  2419 6  0.986407  0.0460431  1  1  -1  -1 
molecular_function  L-ornithine transmembrane transporter activity GO:0000064  17668 1  2419 0  0.863086  1  1  1  -1  -1 
molecular_function  S-adenosylmethionine transmembrane transporter activity GO:0000095  17668 1  2419 0  0.863086  1  1  1  -1  -1 
+1

只是要清楚,文件頭不是什麼會導致重複的'row.names'(header ='col.names') – 2013-03-08 01:32:31

+0

哦好吧,.. o.O我該如何強制導入?是的,這可能是我的數據的一排孔是相同的。我附上了上面的文件的一個例子。那麼如何強制? – Smoki 2013-03-08 01:34:22

+1

重複的行名稱,而不是重複的行 – 2013-03-08 01:36:29

回答

9

根據R文檔here

If there is a header and the first row contains one fewer field 
than the number of columns, the first column in the input is used 
for the row names. Otherwise if row.names is missing, the rows are numbered. 

...因此我建議,第一行可以有一個減少現場比列的數量,所以read.table()是作爲選擇的第一列(其中包含molecular_function多個副本)行名稱。

+0

uhh我試過了: head -n 10 groups.txt | cat --show-tabs 而且看起來有些人寫了那個生成文件的原始程序,在行尾添加了\ t。它看起來像: – Smoki 2013-03-08 01:59:22

+3

'read.table()'是一個非常聰明和方便的功能,但我認爲有時它對於它自己的好(或者對我們來說可能是太好),當文件格式不是相當我們所期望的... – Simon 2013-03-08 02:28:28

0

我遇到了同樣的問題,問題是我的文本文件底部有一噸的表格空白。因此,每行的名稱在這些行上都是相同的(即空白)。因此發生,因爲我從Excel轉換。

1

@adrianoesch的答案(https://stackoverflow.com/a/22408965/2236315)應該有所幫助。

請注意,如果您在某些文本編輯器中打開,則應該看到標題字段的數量少於標題行下方的列數。在我的情況下,數據集有一個「,」在最後一個標題字段末尾丟失。

0

我已經自動生成了數據文件,除了標題以外,只有一列空了。我不想單獨編輯每個文件(並冒着弄髒它的風險)。我找到的最佳解決方法是在#4066607的問題中,在參數中包含「row.names = NULL」。

DF<-read.csv(file, ..... , row.names=NULL) 

這並不完美,但讓我加載文件。與其他答案中描述的行爲不同(強制添加一列額外的行號),我得到原始的第一列標記爲「row.names」,並且所有標題向右移動了一列....但它讓我獲取所有數據。

相關問題