Skip to content

NA values with stringsAsFactors = true #1466

Closed

Description

@JamesOwers

If I run fread specifying na.strings is this not respected by stringsAsFactors? I see in the code that as.factor is called without the exclude= argument.

I'm asking because I get factors with NA as one of the levels. This means DT[is.na(factorcol),] returns no rows which is not what I was expecting. The workaround it to use DT[is.na(levels(factorcol)),]

Activity

  1. arunsrinivasan commented on Dec 11, 2015

    @arunsrinivasan
    Member

    I don't fully understand this. There's no reproducible example or version number. But I think its duplicate of #1408 and news item 14 under bug fixes for v1.9.7. We don't use as.factor() but our own as_factor().

    Please try with devel version before posting.

    # v1.9.7 (latest commit)
    require(data.table)
    fread('a,b\na,2\nb,3\nc,4\nNA,5\n', stringsAsFactors=TRUE, na.strings=c("NA", "c"))[is.na(a)]
    #     a b
    # 1: NA 4
    # 2: NA 5

    If I seem to have misunderstood, please explain with a reproducible example. Thanks.

  2. JamesOwers commented on Dec 11, 2015

    @JamesOwers
    Author

    Exactly what I needed. Many thanks. Your mind reading skills are on point. Apologies for poor description 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions