Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

duplicate 'row.names' are not allowed error

Tags:

r

r-faq

csv

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.

like image 599
george willy Avatar asked Jan 13 '12 16:01

george willy


People also ask

How do I fix duplicate row names are not allowed?

The way to fix this error is to simply use row. names=NULL when importing the file: What is this? We are able to successfully import the CSV file, but the column names are off.

How do I remove duplicate row names in R?

Remove Duplicate rows in R using Dplyr – distinct () function. Distinct function in R is used to remove duplicate rows in R using Dplyr package. Dplyr package in R is provided with distinct() function which eliminate duplicates rows with single variable or with multiple variable.

How do I create a duplicate row?

Duplicate Rows – Copy and Paste Say you have the following data set and want to copy Row 7 to Row 8. 1. Select the row you want to copy by clicking on a row number (here, Row 7), then right-click anywhere in the selected area and choose Copy (or use the keyboard shortcut CTRL + C).

How do I set row names in R?

Method 1 : using rownames() A data frame's rows can be accessed using rownames() method in the R programming language. We can specify the new row names using a vector of numerical or strings and assign it back to the rownames() method.


1 Answers

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) 
like image 136
Dirk Eddelbuettel Avatar answered Sep 21 '22 13:09

Dirk Eddelbuettel