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

level order for melt.array #19

Closed
knokknok opened this issue May 25, 2012 · 5 comments
Closed

level order for melt.array #19

knokknok opened this issue May 25, 2012 · 5 comments

Comments

@knokknok
Copy link

Since arrays row/column/... order can be meaningful, it would be nice to have an option in melt.array to be able to have the levels of factors generated from dimnames to be in the original array order.

@hadley
Copy link
Owner

hadley commented Mar 10, 2014

That's the default with as.is = FALSE

@hadley hadley closed this as completed Mar 10, 2014
@knokknok
Copy link
Author

As I understand it, as.is = FALSE converts dimnames to factors. However the levels of the factors are the ordered strings.
What I was looking for is levels in the initial order of the row/col-names: factor(colnames(x), levels=unique(colnames(x)))

@hadley
Copy link
Owner

hadley commented Mar 11, 2014

Ah, good point - I only checked with arrays that already had sorted names. It would be helpful if you could contribute a couple of examples of expected behaviour.

@hadley hadley reopened this Mar 11, 2014
@knokknok
Copy link
Author

A bit convoluted but:

data <- matrix(rnorm(40), ncol=4, dimnames=list(paste0("S", 1:10), paste0("1", c("", "0", "00", "000"), "g/ml")))
df <- melt(data, varnames=c("Sample", "Concentration"))
# default:
ggplot(df, aes(x=Concentration, y=value))+geom_point()
# ordered as in the matrix:
df$Concentration <- factor(df$Concentration, levels=colnames(data))
ggplot(df, aes(x=Concentration, y=value))+geom_point()

@hadley
Copy link
Owner

hadley commented Mar 14, 2014

Here's a slightly simpler case:

library(reshape2)

data <- matrix(1:12, c(3, 4))
dimnames(data) <- list("x" = letters[3:1], y = LETTERS[4:1])

str(melt(data))

@hadley hadley closed this as completed in d4369cf Apr 22, 2014
duncandoo pushed a commit to duncandoo/reshape that referenced this issue Jun 23, 2014
duncandoo added a commit to duncandoo/reshape that referenced this issue Jun 23, 2014
* upstream/master: (70 commits)
  corrected argument to `install_github`
  Add note to NEWS
  Handle 'no measure.variables' case; closes hadley#46
  Bump version
  Fix license typo
  Bump version
  Add r cmd check notes
  Tweak news
  Code outside link, not inside :(
  Re-document
  Use new testthat structure
  Preserve order of dimnames. Closes hadley#19
  Update urls
  Use dcast, not cast, in recast. Closes hadley#45
  Depend on plyr 1.8.1. Closes hadley#44
  Make sure OBJECT bit is set when 'value' is a factor
  Update NEWS
  Use $ instead of [[
  Include updated args in melt_check roxygen
  Some more tweaks + robustness
  ...

Conflicts:
	DESCRIPTION
	man/guess_value.Rd
	man/margins.Rd
	man/melt.array.Rd
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

2 participants