Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

duplicate columns header in data frame in R

Tags:

r

I have 4 duplicate column names in my dataframe. When I read the file, R automatically appends .1 or .2 to my duplicate columns Original table -

Date       Temp Press Probability Press Probability
11/4/2015   100   45      0.65      55     0.85

What R is currently doing -

Date       Temp  Press   Probability  Press.1  Probability.1
11/4/2015   100   45      0.65           55     0.85

I don't want R to add .1 to my duplicate columns. Is there a way I can avoid that and keep my parameter name as-is? Please advise Thanks

like image 386
SAS Avatar asked Nov 04 '15 15:11

SAS


1 Answers

When calling data.frame(), you can specify the parameter check.names = FALSE. Like in :

data.frame(foo = 1:3, foo = 2:4, check.names = FALSE)

However, it is often better to avoid duplicates in column names.

like image 158
jlesuffleur Avatar answered Oct 21 '22 02:10

jlesuffleur