Skip to content

bind_cols() allows duplicate column names #2248

@tiernanmartin

Description

@tiernanmartin

As @hadley noted, this is likely a bug.

df1 <- mtcars %>% select(mpg,cyl,disp) %>% slice(1:5)
df2 <- mtcars %>% select(mpg,hp,drat) %>% slice(6:10)

names(one);names(two)
## [1] "mpg"  "cyl"  "disp"
## [1] "mpg"  "hp"   "drat"

df_combined <- bind_cols(df1,df2)

df_combined
## mpg cyl disp  mpg  hp drat
## 1 21.0   6  160 18.1 105 2.76
## 2 21.0   6  160 14.3 245 3.21
## 3 22.8   4  108 24.4  62 3.69
## 4 21.4   6  258 22.8  95 3.92
## 5 18.7   8  360 19.2 123 3.92

df_combined %>% select(mpg)
## Error: found duplicated column name: mpg

Seems like a good opportunity to add a suffix argument, as seen in the dplyr::*_join() verbs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions