Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reading a csv file with repeated row names in R

Tags:

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.

like image 898
baz Avatar asked Nov 01 '10 04:11

baz


People also ask

What does duplicate row names are not allowed mean in R?

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.

Can you have duplicate row names in R?

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.

What does row names 1 do in R?

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.

What does the read CSV () function in R do?

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.


1 Answers

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) 
like image 176
doug Avatar answered Sep 28 '22 04:09

doug