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 when id.vars = NULL #2502

Open
Henrik-P opened this issue Nov 25, 2017 · 1 comment
Open

melt when id.vars = NULL #2502

Henrik-P opened this issue Nov 25, 2017 · 1 comment
Labels
reshape dcast melt

Comments

@Henrik-P
Copy link

Henrik-P commented Nov 25, 2017

melt a data.table where all variables are measure.vars without specifying id.vars or measure.vars, works fine, but triggers a (relevant and informative) warning*:

library(reshape2)
library(data.table)
dt <- data.table(x1 = 1, x2 = 2, x3 = 3)
melt(dt)
#    variable value
# 1:       x1     1
# 2:       x2     2
# 3:       x3     3
# Warning message:
#   In melt.data.table(dt) :
#   To be consistent with reshape2's melt, id.vars and measure.vars are internally guessed when both
# are 'NULL'. All non-numeric/integer/logical type columns are conisdered id.vars, which in this case
# are columns []. Consider providing at least one of 'id' or 'measure' vars in future.

"id.vars and measure.vars are [...] both [...] NULL". So let's try to set id.vars = NULL because the data contains measure.vars only:

melt(dt, id.vars = NULL)

Same warning.

Try similar in reshape2::melt; id/measure.vars not specified, generates a warning:

dt <- as.data.frame(dt)
melt(df)
# No id variables; using all as measure variables
#   variable value
# 1       x1     1
# 2       x2     2
# 3       x3     3

Setting id.vars = NULL removes the warning:

melt(df, id.vars = NULL)
#   variable value
# 1       x1     1
# 2       x2     2
# 3       x3     3

Should id.vars = NULL in data.table::melt work like in reshape2::melt, i.e. result in no "guessing" of id/measure.vars and no warning, "To be consistent with reshape2's melt"?


*Please note the typo in the warning: "conisdered" should be "considered"

@MichaelChirico
Copy link
Member

somewhat related: #1699

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

No branches or pull requests

3 participants