Last active
January 3, 2023 12:18
-
-
Save danlewer/44ad7f79d7b090910b9de888856f7ddf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
which.median <- function (x, ties.method = c('first', 'last', 'random', 'all'), ...) { | |
med <- median(x, ...) | |
dif <- abs(med - x) | |
ind <- which(dif == min(dif)) | |
if (length(ind) > 1 & ties.method[1] != 'all') { | |
ind <- if (ties.method[1] == 'first') ind[1] else {if (ties.method[1] == 'last') tail(ind, 1) else sample(ind, 1)} | |
} | |
return (ind) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment