Created
February 23, 2017 00:40
-
-
Save johnmyleswhite/8651299055752ab9e9724a812df3e7a9 to your computer and use it in GitHub Desktop.
R's Medians as a Rabbit Hole of Type Promotions and Function Indirection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> median(FALSE) | |
[1] FALSE | |
> median(c(TRUE, FALSE)) | |
[1] 0.5 | |
> median(c(TRUE, FALSE, TRUE)) | |
[1] TRUE | |
> f <- factor(c('a', 'b', 'c'), levels = c('a', 'b', 'c'), ordered = TRUE) | |
> median(f) | |
Error in median.default(f) : need numeric data | |
> median(c('a', 'b')) | |
[1] NA | |
Warning message: | |
In mean.default(sort(x, partial = half + 0L:1L)[half + 0L:1L]) : | |
argument is not numeric or logical: returning NA | |
> median(c('a', 'b', 'c')) | |
[1] "b" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment