0

Possible Duplicate:
data.table - join NA keys

I have already asked this question, but didn't get any good answers. If I join two data.tables which contain NA keys I get something unexpected.

a = data.table(a=c(NA,1,11,NA,NA),aa=c(0,11,333,3,5))
b = data.table(a=c(NA,1,33,2),bb=c(11,NA,100,3))
merge(a,b,by="a",all.x=T)
    a  aa bb
1: NA   0 NA
2: NA   3  3
3: NA   5  3
4:  1  11 NA
5: 11 333 NA

which should be identical to

merge(b,a,by="a",all.y=T)
    a bb  aa
1: NA 11   5
2: NA NA   0
3: NA NA   3
4:  1 NA  11
5: 11 NA 333

interestingly none of them are what you'd expect to get as an output.

Community
  • 1
  • 1
jamborta
  • 5,130
  • 6
  • 35
  • 55
  • Please don't repost questions. Use a [bounty](http://stackoverflow.com/faq#bounty) to attract attention to the original. That being said, the answer I posted (to the original) and the link explains why it won't work. – mnel Nov 28 '12 at 11:23
  • Thanks, I understand that it doesn't work, I'm after understating what to expect as an output instead. – jamborta Nov 28 '12 at 11:29
  • 3
    You can *expect* output that doesn't make sense. (Perhaps you could expect an error message) – mnel Nov 28 '12 at 11:33
  • The feature of joins/merges on NA/NaNs have been implemented in v1.8.11. Check out [**this post**](http://stackoverflow.com/questions/12646172/select-na-in-a-data-table-in-r/20590133#20590133) for more info. Although your question on these two merges having the same output doesn't make sense. – Arun Dec 15 '13 at 01:13

0 Answers0