-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Milestone
Description
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.
mattdowle