Skip to content

Possibility to provide group labels in melt variable column when melting a list of columns simultaneously #2551

@matthiasgomolka

Description

@matthiasgomolka

Right now, there is a loss of information when one melts a list of columns simultaneously since the variable column only gives the number of the group (as a factor by default), not a name.

It would be great if the functionality of melting a list of columns simultaneously would be extended such that it is possible to provide labels for the factor in the variable ###column. I would suggest an additional argument, e.g. variable.labels which makes it possible to provide custom labels.

# Minimal reproducible example

library(data.table)

DT <- data.table(val_loss = 1:2,
                 val_acc = 3:4,
                 loss = 5:6,
                 acc = 7:8,
                 id = c("A", "B"))

DT_melted <- 
  melt(DT,
       measure.vars = list(c("loss", "acc"), c("val_loss", "val_acc")),
# the following line shows what I think would be ideal
#      variable.labels = c("group 1", "group 2"),
       value = c("training", "validation"))

# the following step should become obsolete by providing the labels during the melt call above
DT_melted[, variable := factor(variable, levels = 1:2, labels = c("group 1", "group 2"))]

# Output of sessionInfo()

R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.10.4-3

loaded via a namespace (and not attached):
[1] tools_3.3.3

I know that the R Version is not up to date but at my Company it takes a while until we get the most recent version.

Sorry, for not labeling the issue. Somehow I could not figure out, how to set them.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions