Skip to content

Join using on not working when specifying column names #2094

Description

@jrowen

This example doesn't appear to work.

X = data.table(A=LETTERS[1:10], value1=1:10)
Y = data.table(B=LETTERS[1:10], value2=11:20)
X[Y, on=c(x="A", y="B")]

But the data.table help for on appears to say that it should work: "As a named character vector, e.g., X[Y, on=c(x="a", y="b")]. This is useful when column names to join by are different between the two tables."

From what I can see in the code, it appears that the on names are not used when checking is columns are present.

Activity

  1. franknarf1 commented on Mar 31, 2017

    @franknarf1
    Contributor

    The lower-case x and y are meaningful there. They should be column names in X. Similarly, a and b should be column names in Y.

    The line you found in the code shows the cols of X being selected. Try names(c(x="A", y="B")) if you're not familiar with that function already. Similarly, the leftcols line soon after shows cols of Y being selected (try unname(c(x="A", y="B")))...

  2. jrowen commented on Mar 31, 2017

    @jrowen
    Author

    Thanks for the quick response. With this additional info, I've confirmed that everything works. I was getting confused by the fact that the lowercase names matched the table names, so my only suggestion might be to clarify the help text a bit more (the second and third lines of your comment are really helpful).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions