Skip to content

Instantly share code, notes, and snippets.

@ateucher
Created April 28, 2015 20:14
Show Gist options
  • Save ateucher/6bae26e608b996b065d1 to your computer and use it in GitHub Desktop.
Save ateucher/6bae26e608b996b065d1 to your computer and use it in GitHub Desktop.
pmax_with_factors.md
```r
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
```
```r
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