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

前端 未结 5 1957
逝去的感伤
逝去的感伤 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 20:52

    If anyone else comes across this problem, my issue was that there were blank spaces in certain columns. After filling these spaces, my issue went away and I was able to load the .csv file just fine.

    0 讨论(0)
  • 2020-12-31 21:01

    I was having the same problem. I merged the date with timestamps and now I am able to read from the csv.

    You can generate a row number as the first column (say using python) in your csv and then read it again.

    0 讨论(0)
  • 2020-12-31 21:04

    had the same problem. just added this line:

    colnames(rec) <- c(colnames(rec)[-1],"x")
    rec$x <- NULL
    
    0 讨论(0)
  • 2020-12-31 21:12

    I used the following code:

    lm.table  <- read.table("file name", header=TRUE, row.names=NULL)
    

    This added a column to the left with numbered row names, but I didn't find that the column names were shifted. Could it be that your column names still matched the right columns, but the R output made it look like the names had shifted?

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题