-
Notifications
You must be signed in to change notification settings - Fork 977
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 Function Inconsistency with reshape2 Version #780
Comments
@dardesta, thanks for the report. But, could you please provide a minimal reproducible example - what's |
Sure. I'll use the data.table example. library(reshape2)
library(data.table)
DF = data.frame(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)
DT = data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)
transpose = function(input, by, var, id, varName="variable", valueName="value"){
melt(input, id.vars = by, measure.vars=var)
}
#Data frame test
transpose(DF, by="x")
transpose(DF)
#Data table test
transpose(DT, by="x")
transpose(DT) |
@dardesta, great example! Thanks. Was easy enough to fix now (although just to be consistent with |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a transpose function that imitates the arguments used in SAS.
transpose = function(input, by, var){
melt(input, id.vars = by, measure.vars=var)
}
Function Call
transpose(myData, by="Year")
This function works if myData is a data frame, but it returns an error if myData is a data table.
Error in melt.data.table(input, id.vars = by, measure.vars = var) :
argument "var" is missing, with no default
This will work if I default var to a NULL value, but then the data frame version will result in an error.
My question is: Is there a reason for the inconsistency? It would be nice to have melt.data.table suppor missing arguments so that there is not a need for the programmer to check the class of myData.
The text was updated successfully, but these errors were encountered: