Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't assign NA for a factor #1740

Closed
Zus opened this issue Jun 14, 2016 · 2 comments
Closed

Can't assign NA for a factor #1740

Zus opened this issue Jun 14, 2016 · 2 comments
Assignees
Milestone

Comments

@Zus
Copy link

Zus commented Jun 14, 2016

When trying to assign NA to a specfic items in a factor, an error is thrown, which does not happen in base DF.

require(data.table)
DT <- data.table(x = 1:5,y = factor(c("","a","b","a", "")), z = 5:9)
DT[y==""]
DT[y=="", y := NA] # throws an error, interpreted as logical
DT[y=="",y] <- NA # throws an error

R 3.3.0 DT 1.96

@jangorecki
Copy link
Member

jangorecki commented Jun 14, 2016

It works if you provide a factor type value on RHS of :=, this can be done with as.factor(NA) or even as.integer(NA) (because factor is of integer type):

DT[y=="", y := as.factor(NA)]

But I agree to make sense to catch that automatically.

@arunsrinivasan
Copy link
Member

It was expecting an integer (NA_integer_). But the coercion is handled on logical types as well.

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

No branches or pull requests

3 participants