Skip to content

Merge with NA in factor key copies NA row #945

Closed

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.

Activity

  1. arunsrinivasan commented on Nov 11, 2014

    @arunsrinivasan
    Member

    @stewbasic thanks for the nice minimal example.

  2. added this to the v1.9.8 milestone on Dec 4, 2014
  3. modified the milestones: v1.9.6, v1.9.8 on Feb 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions