Skip to content

fixed merge by.y with duplicate column names. Fixes #637 - #1176

Closed
blasern wants to merge 1 commit into
Rdatatable:masterfrom
blasern:master
Closed

blasern wants to merge 1 commit into
Rdatatable:masterfrom
blasern:master

Conversation

@blasern

@blasern blasern commented Jun 10, 2015

Copy link
Copy Markdown

I have fixed the problem with duplicate column names using the same approach used for other duplicate names (see here and here) in merge.data.table.

Note that there is still a difference to merge.data.frame, but in my opinion this behavior is preferable. The data.frame version does not append the suffixes to the duplicate name that occur in by.x and gives a warning. The new version of merge.data.table does append the suffix to that column and runs without warnings:

require(data.table)
dt1 = data.table(w = 0, x=1:2, y=3:4, z=5:6)
dt2 = copy(dt1)
merge(dt1, dt2, by.x="z", by.y="w", all = TRUE)
##    z  w x.x y.x x.y y.y z.y
## 1: 0 NA  NA  NA   1   3   5
## 2: 0 NA  NA  NA   2   4   6
## 3: 5  0   1   3  NA  NA  NA
## 4: 6  0   2   4  NA  NA  NA

df1 = data.frame(w = 0, x=1:2, y=3:4, z=5:6)
df2 <- df1
merge(df1, df2, by.x="z", by.y="w", all = TRUE)
##   z  w x.x y.x x.y y.y  z
## 1 0 NA  NA  NA   1   3  5
## 2 0 NA  NA  NA   2   4  6
## 3 5  0   1   3  NA  NA NA
## 4 6  0   2   4  NA  NA NA
## Warning message:
##   In merge.data.frame(df1, df2, by.x = "z", by.y = "w", all = TRUE) :
##   column name ‘z’ is duplicated in the result

@arunsrinivasan

Copy link
Copy Markdown
Member

Thanks again @blasern, but couldn't merge as tests failed.

Took care of this in 44b1e00 when incorporating the on= functionality for merge.data.table to not copy anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants