Revision 03698027c2d84118bd0c53c4a9a5b5d23676f388 authored by HwB on 01 October 2012, 00:00:00 UTC, committed by Gabor Csardi on 01 October 2012, 00:00:00 UTC
1 parent 9fdea5d
mode.R
##
## m o d e . R
##
Mode <- function(x) {
if (is.matrix(x))
x <- c(x)
if (is.numeric(x)) {
x <- sort(x)
tbl <- table(x)
n <- which.max(tbl)
xm <- as.numeric(names(tbl)[n])
} else if (is.complex(x)) {
x <- x[order(abs(x))]
tbl <- table(x)
n <- which.max(tbl)
xm <- as.complex(names(tbl)[n])
} else if (is.factor(x)) {
tbl <- table(x)
n <- which.max(tbl)
xm <- names(tbl)[n]
} else
xm <- NA
return(xm)
}
Computing file changes ...