Hi everyone, To revive the discussion Gabor started here: http://r.789695.n4.nabble.com/Problem-with-FAQ-2-8-tt4668878.html and the (related, but subtly different) FR mnel filed here: https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2693&group_id=240&atid=978
Suppose you have: require(data.table) d1 <- data.table(id1 = c(1L, 2L, 2L, 3L), val = 1:4, key = "id1") d2 <- data.table(id2 = c(1L, 2L, 4L), val2 = c(11, 12, 14),key = "id2") Then as Gabor points out: `d1[d2, id1]` should *not* result in an error, because FAQ 2.8 states (copied from Gabor's post linked above): 1. The scope of X's subset; i.e., X's column names. 2. The scope of each row of Y; i.e., Y's column names (join inherited scope) … In this case, the desired output for `d1[d2, id1]` should then be: id1 id1 1: 1 1 2: 2 2 3: 2 2 4: 4 NA That's what I at least understand from what the documentation intends. However, this recommends a subtle change to the current method of referring to columns, if we were to keep this idea. That is, consider the data.table "d3" as follows: d3 <- copy(d2) setnames(d3, names(d1)) Now, what should `d1[d3, id1]` give? The answer, I believe, is same as `d1[d2, id1]`. Why? Because, X's (here d1's) column names should be looked up first (as per FAQ 2.8). Therefore, corresponding to d2=c(1,2,4), the values for "id1" are c(1, (2,2), NA). Now, if the old behaviour is to be intended - here comes the "subtle change", then one should do: d1[d3, i.d1] # referring to i's variables with the "i." notation. I've managed to implement the first part where X's columns are looked up so that `d1[d2, id1]` doesn't result in error. However, I'd like to ensure that my understanding of the FAQ is right (and that the FAQ makes sense - it does to me). Please let me know what you all think so that I can implement the second part and commit. This, I believe will let us get a step closer to the consistency in DT syntax. Arun
_______________________________________________ datatable-help mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
