# how to creat a data.frame with Duplicate column names

#### guozihuaa

##### New Member
I want to creat a data frame with the Duplicate column names, and it also contain rownams which are not Duplicate. The following is my code.
colnames(X) <- c("good", "good")
row.names(X)<-c("a","b","c")
who can help me? Thank you very much.

#### Dason

You can use check.names=FALSE when creating data.frame to allow duplicate column names (or even typically 'illegal' column names). You can also specify row names during the creation of the data.frame
Code:
> data.frame(good = 1:3, good = rnorm(3), row.names = letters[1:3], check.names = FALSE)
good       good
a    1  0.1790414
b    2 -0.7946657
c    3 -1.3426408

#### guozihuaa

##### New Member
Thank you very much,you are so nice. But I still have a problem, because I think your answer is not suitable for my problem. I have a file whose format is csv, and the file have some duplicate column names. First, I import it with the command read.csv("df.csv",head=T), and I want to add the row names directly, how can I do this? Than you very much

#### guozihuaa

##### New Member
You can use check.names=FALSE when creating data.frame to allow duplicate column names (or even typically 'illegal' column names). You can also specify row names during the creation of the data.frame
Code:
> data.frame(good = 1:3, good = rnorm(3), row.names = letters[1:3], check.names = FALSE)
good       good
a    1  0.1790414
b    2 -0.7946657
c    3 -1.3426408
Thank you very much,you are so nice. But I still have a problem, because I think your answer is not suitable for my problem. I have a file whose format is csv, and the file have some duplicate column names. First, I import it with the command read.csv("df.csv",head=T), and I want to add the row names directly, how can I do this? Than you very much