As advised, I used some code samples in another forum, but it could not improve the problem. My question is the “duplicate ‘row.names’ are not allowed” in R – how to solve it? The command line is:
StartDate, var1, var2, var3, ..., var14
systems <- read.table("http://getfile.pl?test.csv", header = TRUE, sep = ",")
and the result:
duplicate row.names are not allowed
What does the message mean? Can you advise me to fix it? If you have other better answers, leave them in the answer box below.
After looking over your problem, I find that except for the header row, each row in the file ends with a comma. This makes R misunderstand that the row names are in the 1st values column.
The easiest way to solve this error is require read.table not to apply
You can see all your numbered rows after doing this.
Then let’s check out
read.csv, a wrapper for
read.tablethat has the
header=TRUEarguments configured previously, making your call easier to:
The related question highlights a section of
?read.tabledocumentation that answers your problem.
The header row is likely to have 1 less column than the rest of your file. Therefore
read.tableassumes the first column is the one.names (which must be unique), and not a column (which may contain duplicated value). This can be fixed by one of these two solutions:
,to the front or the end of your header row within the source file.
Your data structure will determine which option you make.
Example: The header row is taken to mean that there is one less column than the data, because the delimiters aren’t compatible:
This is how it’s interpreted by default
The values of the first column (without headers) are interpreted as row.names
b1. This error can be caused by duplicates in this column, which is possible.
You can set
row.names = FALSEto make the shift not occur, but there is still a mismatch between the items in the header, and the data, because the delimiters aren’t compatible.
Solution 1 Add trailing separator to header
Solution 2 Removing trailing delimiter in non-header rows