Skip to content

Strange behavior for filtering in data.table with NA values #1252

@sergiizaskaleta

Description

@sergiizaskaleta

Reported from this SO question:
I've stumbled upon weird data table i behavior that returns a row with NAs where I would expect an empty data table. See:

a = data.table(a = 1, d = NA) 
a[!is.na(a) & d == "3"] 
#     a  d
#1: NA NA

I would expect an empty data table as a result here.
Compare to:

a = data.table(a = c(1,2), d = c(NA,3))
a[!is.na(a) & d == "3"] 
#    a d
#1: 2 3

This one does not produce an extra row with NA values, though.

> sessionInfo()
# R version 2.15.2 (2012-10-26)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# 
# locale:
# [1] LC_COLLATE=English_United Kingdom.1252 
# [2] LC_CTYPE=English_United Kingdom.1252
# 
# [3] LC_MONETARY=English_United Kingdom.1252
# [4] LC_NUMERIC=C
# 
# [5] LC_TIME=English_United Kingdom.1252
# 
# attached base packages:
# [1] stats graphics grDevices utils datasets methods base

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions