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.
names' are not allowed. This error usually occurs when you attempt to read a CSV file into R that contains commas at the end of every row in the file except the header row.
It is not possible to have duplicate row names, but a simple workaround is creating an extra column (e.g. label) that holds the name that you would assign to your rows.
Assigning the second argument, row. names , to be 1 indicates that the data file has row names, and which column number they are stored in. If we don't specify row. names the result will not have row names.
csv() Function. read. csv() function in R Language is used to read “comma separated value” files. It imports data in the form of a data frame.
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".
read.csv("S1N657.csv", header=T,fill=T, col.names=c("dam","anim","temp"), row.names=NULL)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With