Skip to content

melt.data.table inconsistent with reshape2::melt #1699

@MichaelChirico

Description

@MichaelChirico

See this SO Q&A.

Here's what works in reshape2:

buyer      <- c("A", "A", "B", "A", "B", "C")
seller     <- c("C", "B", "C", "B", "C", "A")
negotiator <- c("B", "C", "D", "D", "A", "B")

df <- data.frame(buyer, seller, negotiator)
reshape2::melt(df,0)
#      variable value
#1       buyer     A
#2       buyer     A
#3       buyer     B
#4       buyer     A
#5       buyer     B
#6       buyer     C
#7      seller     C
#8      seller     B
#9      seller     C
#10     seller     B
#11     seller     C
#12     seller     A
#13 negotiator     B
#14 negotiator     C
#15 negotiator     D
#16 negotiator     D
#17 negotiator     A
#18 negotiator     B

But that's an error in melt.data.table:

setDT(df)
melt(df, 0)

Error in melt.data.table(df, 0) :
One or more values in id.vars is invalid.

This is fine, as we can simply set measure.vars = names(df), but IIUC we're aiming for melt.data.table to subsume reshape2::melt.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions