I am trying to read a csv file with repeated row names but could not. The error message I am getting is Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed.
The code I am using is:
S1N657 <- read.csv("S1N657.csv",header=T,fill=T,col.names=c("dam","anim","temp"))
An example of my data is given below:
did <- c("1N657","1N657","1N657","1N657","1N657","1N657","1N657","1N657","1N657","1N657")
aid <- c(101,102,103,104,105,106,107,108,109,110)
temp <- c(36,38,37,39,35,37,36,34,39,38)
data <- cbind(did,aid,temp)
Any help will be appreciated.
try this:
In short, check your column names. If your first row is the names of columns, you may be missing one or more names.
Example:
The example above will cause a row.name error because each row has 4 values, but only 3 columns are named.
This happened to me when I was building a csv from an online resources.
Guessing your csv file was one converted from xlsx.Add a comma to the end of the first row ,remove the last row ,done
in my case the problem came from the excel file. Although it seemed perfectly organized, it did not worked and I had always the message:
Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed.
I tried to copy-paste my excel matrix to a new empty excel sheet and I retried to read it: it worked ! No error message anymore !
the function is seeing duplicate row names, so you need to deal with that. Probably the easiest way is with row.names=NULL, which will force row numbering--in other words, it treats your first column as the first dimension and not as the row numbers, and so adds row numbers (consecutive integers starting with "1".
An issue I had recently was that the number of columns in the header row did not match the number of columns I had in the data itself. For example, my data was tab-delimited and all of the data rows had a trailing tab character. The header row (which I had manually added) did not.
I wanted the rows to be auto-numbered, but instead it was looking at my first row as the row name. From the docs (emphasis added by me):
Adding an extra tab character to the header row made the header row have the same number of columns as the data rows, thus solving the problem.