I\'m trying to reorder the rows of a data frame by two factors. For the first factor i\'m happy with the default ordering. For the second factor i\'d like to impose my own c
Reordering the factor levels:
dat[with(dat, order(orange, as.integer(factor(apple, appleOrdered)))), ]
Try using a factor with the levels in the desired order and the arrange function from plyr:
arrange
plyr
dat$apple <- factor(dat$apple,levels=appleOrdered) arrange(dat,orange,apple)