Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"on=" doesn't retain keys correctly. #1268

Closed
arunsrinivasan opened this issue Aug 13, 2015 · 3 comments
Closed

"on=" doesn't retain keys correctly. #1268

arunsrinivasan opened this issue Aug 13, 2015 · 3 comments
Assignees
Labels
Milestone

Comments

@arunsrinivasan
Copy link
Member

Sample data taken from this SO post from Douglas Clark. Thanks for the nice example!

require(data.table)

# main data table DT, keyed on site and date, with data column x
DT <- data.table(site = rep(LETTERS[1:2], each=3),
                 date = rep(1:3, times=2),
                 x = rep(1:3*10, times=2),
                 key = "site,date")
DT
#    site date  x
#1:    A    1 10
#2:    A    2 20
#3:    A    3 30
#4:    B    1 10
#5:    B    2 20
#6:    B    3 30

# lookup table for x to y lookup, keyed on x
x2y <- data.table(x = c(10,20), y = c(100,200), key = "x")
x2y

To join on column x, we don't have to re-key anymore:

DT[x2y, on="x"]
#    site date  x   y
#1:    A    1 10 100
#2:    B    1 10 100
#3:    A    2 20 200
#4:    B    2 20 200

key(DT[x2y, on="x"])
# [1] "site" # <~~~ wrong

It should be x as i here is keyed on that column, and corresponding column in DT is also named x.

@jan-glx
Copy link
Contributor

jan-glx commented Sep 10, 2015

I would prefer if the result was indeed keyed on "site,date".

@arunsrinivasan
Copy link
Member Author

The order of rows in joined result is determined by i. So no, that'd not be possible.

@arunsrinivasan arunsrinivasan added this to the v1.9.8 milestone Sep 22, 2015
@arunsrinivasan arunsrinivasan self-assigned this Mar 9, 2016
@arunsrinivasan
Copy link
Member Author

Updated SO post linked above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants