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

variable should be independent of na.rm when melt into multiple columns #4455

Closed
tdhock opened this issue May 17, 2020 · 3 comments · Fixed by #4723
Closed

variable should be independent of na.rm when melt into multiple columns #4455

tdhock opened this issue May 17, 2020 · 3 comments · Fixed by #4723
Labels
Milestone

Comments

@tdhock
Copy link
Member

tdhock commented May 17, 2020

Hi I have noticed an inconsistency in the behavior of melt when measure.vars is a list (so multiple value columns appear in the result).
Here is a minimal reproducible example:

library(data.table)
wide.dt <- data.table(
  family=1,
  age_child1=NA_real_, sex_child1=NA_character_,
  age_child2=5, sex_child2="m")
measure.vars <- list(age=c(2,4), sex=c(3,5))
(na.rm.T <- melt(wide.dt, measure.vars=measure.vars, na.rm=TRUE))
(na.rm.F <- melt(wide.dt, measure.vars=measure.vars, na.rm=FALSE)[!is.na(age)])

On my system I get:

> (na.rm.T <- melt(wide.dt, measure.vars=measure.vars, na.rm=TRUE))

   family variable age sex
1:      1        1   5   m
> (na.rm.F <- melt(wide.dt, measure.vars=measure.vars, na.rm=FALSE)[!is.na(age)])
   family variable age sex
1:      1        2   5   m

I expected variable=2 in both cases, but variable=1 with na.rm=TRUE, which I believe is incorrect/buggy.
At the very least this behavior is confusing. I expected that variable in the output should corresponding to the index of the corresponding column in the measure.vars list (2).

There are a few other issues open about melt into multiple columns but after reviewing them they all seem to be different.

@jangorecki jangorecki added the reshape dcast melt label May 17, 2020
@tdhock
Copy link
Member Author

tdhock commented Sep 24, 2020

hi again, any plan to fix this issue? seems like it should be easy, I could try to fix it myself, but it would be nice if somebody tells me where to look...

@tdhock
Copy link
Member Author

tdhock commented Sep 29, 2020

closing since #4723 fixes this.

@tdhock tdhock closed this as completed Sep 29, 2020
@jangorecki
Copy link
Member

We should close issue when PR is merged, let's keep it open till then.

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

Successfully merging a pull request may close this issue.

3 participants