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

[R-Forge #5072] Merging using character and factor results in by column becoming NA #499

Closed
arunsrinivasan opened this issue Jun 8, 2014 · 0 comments
Assignees
Milestone

Comments

@arunsrinivasan
Copy link
Member

Submitted by: Abiel Reinhart; Assigned to: Arun ; R-Forge link

When using merge() with option all.x=TRUE or all=TRUE, if the column passed to by= is a character in the first data.table, and a factor in the second, then rows in x that are not in y will have their by column value set to NA.

Here's an example. Note how country has become NA in the first example.

require(data.table)
x <- data.table(country="US")
y <- data.table(country="USA")
y$country <- factor(y$country)
merge(x, y, by="country", all=T)
#    country
#1:      NA
#2:     USA

This will not occur if the merging column is a factor in the x input but a character in the y input.

x <- data.table(country="US")
y <- data.table(country="USA")
x$country <- factor(x$country)
merge(x, y, by="country", all=T)
#    country
#1:      US
#2:     USA
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

2 participants