Search code examples
rcsvr-faq

duplicate 'row.names' are not allowed error


I am trying to load a csv file that has 14 columns like this:

StartDate, var1, var2, var3, ..., var14

when I issue this command:

systems <- read.table("http://getfile.pl?test.csv", header = TRUE, sep = ",")

I get an error message.

duplicate row.names are not allowed

It seems to me that the first column name is causing the issue. When I manually download the file and remove the StartDate name from the file, R successfully reads the file and replaces the first column name with X. Can someone tell me what is going on? The file is a (comma separated) csv file.


Solution

  • Then tell read.table not to use row.names:

    systems <- read.table("http://getfile.pl?test.csv", 
                          header=TRUE, sep=",", row.names=NULL)
    

    and now your rows will simply be numbered.

    Also look at read.csv which is a wrapper for read.table which already sets the sep=',' and header=TRUE arguments so that your call simplifies to

    systems <- read.csv("http://getfile.pl?test.csv", row.names=NULL)