不允许R复制'row.names'

时间:2013-03-08 01:17:58

标签: r

这里我的问题在R:

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

第一个文件夹部分或paste()通常由var包装,用于调试目的 - &gt;静态的。

我总是收到消息:

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我认为它来自标题。但是我不想把这些行命名,它只是应该在...中阅读它们.o.O不能那么难,或者?

文件含量:

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

4 个答案:

答案 0 :(得分:10)

根据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的多个副本)作为行名。

答案 1 :(得分:1)

@adrianoesch的答案(https://stackoverflow.com/a/22408965/2236315)应该会有所帮助。

请注意,如果在某个文本编辑器中打开,您应该看到标题字段的数量小于标题行下面的列数。在我的例子中,数据集有一个&#34;,&#34;丢失在最后一个标题字段的末尾。

答案 2 :(得分:0)

我遇到了同样的问题,问题是我的文本文件底部有一吨表格空格。因此,这些行上的每一行名称都相同(即为空白)。因此我发生了因为我从excel转换而来。

答案 3 :(得分:0)

我已自动生成数据文件,其中一列是空的,而不是标题。我不想单独编辑每个文件(并冒险将其弄脏)。我找到的最好的解决方法是问题#4066607,包括&#34; row.names = NULL&#34;在论点中。

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

这不是完美的,但是让我加载文件。与其他答案中描述的行为(强制添加额外的行号列)不同,我得到标记为&#34; row.names&#34;的原始第一列。并且所有标题都向右移动了一列....但是它让我可以获取所有数据。