Last active
January 21, 2016 00:11
-
-
Save noamross/2032675 to your computer and use it in GitHub Desktop.
Ways to find the N minimum value in a vector
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
#Looking for a fast way to find the N minimum values in a vector of values. For use in finding nearest neighbors when one already has a (large) distance matrix. | |
x <- runif(5000) | |
n <- 3 | |
system.time({ # What I'm using now | |
for(i in 1:10000) { | |
a <- sort(x)[1:n] | |
b <- match(a, x) | |
} | |
}) |
davharris
commented
Mar 14, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment