Duplicate 'row.names' error reading table. row.names=NULL shifts columns

前端 未结 5 1983
逝去的感伤
逝去的感伤 2020-12-31 20:11

This is similar to read.csv row.names and to https://stackoverflow.com/questions/12425599/duplicated-row-names , but I do not see answers that help.

Problem: Trying

5条回答
  •  情话喂你
    2020-12-31 21:15

    My problem is associated with field separator for TAB-delimited file:

    If I don't specify the field separator:

    > condensed <- read.table("condense_report.tab", header=T)
     Error in read.table("condense_report.tab", header = T) : 
     duplicate 'row.names' are not allowed
    

    If I add the sep=TAB

    condensed <- read.table("condense_report.tab", header=TRUE, sep="\t")
    

    Then there is no error message.

    Here is my file's content (^I is the TAB character, and $ is the end of line mark):

    Sample^Imethod^Ispecies^Imean_frac^Istd_frac^Imean_dep^Imean_clsz^Inumrep$ asterix_potion^Imothur^IEnterococcus faecalis^I0.32290000^I0.021755985650701942^I3293.5000^I3309.7500^I4$ asterix_potion^Imothur^IAcinetobacter baumannii^I0.28010000^I0.021539851624928375^I2869.5000^I2880.7500^I4$

    The problem is with the species column. It has spaces, and R is using both space and tab as delimiters by default. So you have an extra column than the header according to R if no sep option is given. This is the root of the problem.

提交回复
热议问题