Created
February 14, 2014 14:57
-
-
Save joelgombin/9002444 to your computer and use it in GitHub Desktop.
Nested means discretisation (Scripter, 1970)
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
n_means <- function(x, n) { | |
if (!(log(n, base=2) %% 1 %in% 0)) { | |
stop("The number of classes is not a power of 2.") | |
} | |
index <- rep(1, length(x)) | |
m <- c() | |
for (i in 1:log(n, base=2)) { | |
m <- sort(c(m, tapply(x, index, mean))) | |
index <- findInterval(x, m) | |
} | |
names(m) <- c() | |
return(list(borns = m, classes=index)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment