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

melt(, na.rm=T) doesn't handle NA-columns properly #1359

Closed
mplatzer opened this issue Sep 24, 2015 · 1 comment
Closed

melt(, na.rm=T) doesn't handle NA-columns properly #1359

mplatzer opened this issue Sep 24, 2015 · 1 comment
Assignees
Labels
Milestone

Comments

@mplatzer
Copy link

The code

dt <- data.table(id=1:3, x=NA_character_, y=c('a', NA_character_, 'c'))
melt(dt, id.var='id', na.rm=TRUE)

produces in data.table v1.9.4

   id variable value
1:  1        y     a
2:  3        y     c

but in data.table v.1.9.6 incorrectly returns

   id variable value
1:  1       NA     a
2:  3       NA     c

It seems the bug only occurs when melt is called with na.rm=TRUE on a data.table with a column that purely consists of NA-values. Also note, that the bug does not occur, when the NA-column is the last column of the data.table.

@oseiskar
Copy link
Contributor

There is also something seriously wrong with the resulting NA values:

library(data.table)
dt <- melt(data.table(x='a',y=NA_character_,z='c'), id.var=c('x'), na.rm=T)

melt_na <- dt$variable
regular_na <- as.factor(c(NA_character_,'z'))[1]

Both melt_na and regular_na show as

[1] <NA>
Levels: z

but write.table(melt_na) crashes with the error message

Error in .External2(C_writetable, x, file, nrow(x), p, rnames, sep, eol,  : 
  index out of range

@arunsrinivasan arunsrinivasan added this to the v1.9.8 milestone Sep 25, 2015
@arunsrinivasan arunsrinivasan self-assigned this Sep 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants