Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

level order for melt.array #19

Closed
knokknok opened this Issue · 5 comments

2 participants

@knokknok

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
Owner

That's the default with as.is = FALSE

@hadley hadley closed this
@knokknok

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
Owner

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
@knokknok

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
Owner

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 issue from a commit
@hadley Preserve order of dimnames.
Closes #19
d4369cf
@hadley hadley closed this in d4369cf
@duncandoo duncandoo referenced this issue from a commit in duncandoo/reshape
@hadley Preserve order of dimnames.
Closes #19
ca849b2
@duncandoo duncandoo referenced this issue from a commit in duncandoo/reshape
@duncandoo duncandoo Merge remote-tracking branch 'upstream/master'
* upstream/master: (70 commits)
  corrected argument to `install_github`
  Add note to NEWS
  Handle 'no measure.variables' case; closes #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 #19
  Update urls
  Use dcast, not cast, in recast. Closes #45
  Depend on plyr 1.8.1. Closes #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
cf3f646
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.