2

Possible Duplicate:
Select NA in a data.table in R

just wondering if this is an intended feature or a bug in data.table?

a = data.frame(a=c(NA,1),aa=c(0,11))
b = data.frame(a=c(1),bb=c(11))
merge(a,b,all.x=T,by="a")
   a aa bb
1  1 11 11
2 NA  0 NA

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

same again this way

setkey(b,a)
b[a]
    a bb aa
1: NA 11  0
2:  1 11 11

I'd really expect the behaviour you get with data.frame this case.

thansk

Community
  • 1
  • 1
jamborta
  • 5,130
  • 6
  • 35
  • 55

1 Answers1

4

See FR#1043 Allow or disallow NA in keys?..

It is a known issue, NA values are allowed, but you can't join with them.

See the duplicate question and answer Select NA in a data.table in R for a more detailed description

Community
  • 1
  • 1
mnel
  • 113,303
  • 27
  • 265
  • 254
  • 1
    thanks, but I still don't understand how it gets that value in the join that should be NA (ie bb column)? I think this way results in something very unexpected. – jamborta Nov 23 '12 at 10:04