Skip to content

Merge with NA in factor key copies NA row #945

@stewbasic

Description

@stewbasic

I'm using data.table v1.9.4 on R 3.0.2.

I'm merging two data.tables with a key of type factor containing an NA entry. For keys appearing only in the first table, the columns from the second table don't contain NA, as expected from ?merge, but instead get copied from the NA row. See row 3, column v.y in the following example:

x<-data.table(k=as.factor(c(NA,1,2)),v=c(0,1,2))
y<-data.table(k=as.factor(c(NA,1,3)),v=c(0,1,3))
merge(x,y,all=T,by="k")
#     k v.x v.y
#1: NA   0   0
#2:  1   1   1
#3:  2   2   0
#4:  3  NA   3

This is very similar to the issue reported in this SO post, but it should be fixed as of v1.8.11 according to the comment there.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions