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 behaviour with indexed but non-unique dataframe column names #75

Open
DavoOZ opened this issue Feb 12, 2016 · 1 comment
Open

melt behaviour with indexed but non-unique dataframe column names #75

DavoOZ opened this issue Feb 12, 2016 · 1 comment

Comments

@DavoOZ
Copy link

DavoOZ commented Feb 12, 2016

Hadley et al.,
As a regular user of the excellent reshape2 package, the following behavior of melt() surprised me:

Simple dataframe:
in.df <- data.frame(AA=c(1,2,3), BB=c(10,11,12), CC=c(13,14,15))

melt() works as expected
melt(in.df, id.vars=c(1))

But my dataframe has duplicated (non-unique) column names
names(in.df) <- c("AA","BB","BB")

This doesn't do what I want
melt(in.df, id.vars=c("AA"))

So, I use indexing (rather than renaming the columns).
melt(in.df, id.vars=c(1), measure.vars=c(2,3))

The dimensions are as expected, contents are not.
Should melt_check() abort if measure.vars names are not unique?
if(length(measure.vars) != length(unique(measure.vars))) { stop("names of measure variables are not unique: ", vars, call. = FALSE) }

Thanks again for creating an essential tool.

@DavoOZ
Copy link
Author

DavoOZ commented Feb 12, 2016

I just noticed that this is also the subject of pull request #66.

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

No branches or pull requests

1 participant