Skip to content

Instantly share code, notes, and snippets.

@ateucher
Created April 28, 2015 20:14
Show Gist options
  • Save ateucher/66005fd5c63f46d911ee to your computer and use it in GitHub Desktop.
Save ateucher/66005fd5c63f46d911ee to your computer and use it in GitHub Desktop.
l <- c("a", "b", "c", "d")

a <- factor(c("a", "c", "d"), levels = l, ordered = TRUE)
b <- factor(c("c", "b", "a"), levels = l, ordered = TRUE)

pmax(a, b)
## [1] c c d
## Levels: a < b < c < d
c <- factor(c("a", "c", "d"), levels = l, ordered = FALSE)
d <- factor(c("c", "b", "a"), levels = l, ordered = FALSE)

pmax(c, d)
## Warning in Ops.factor(mmm, each): '<' not meaningful for factors
## [1] a c d
## Levels: a b c d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment