There was a bit of cranial wind-passing in my previous message.
(A bit of redundancy.)
My solution should have read:
diag(M) <- Inf
nn5 <- apply(M,1,function(x){order(x)[1:5]})
What I wrote gave the right answer; there was just a bunch of
unnecessary ring-around-the-rosy playing in it.
Sorry 'bout that.
cheers,
Rolf Turner
-----Oorspronkelijk bericht-----
Van: [email protected] [mailto:[email protected]] Namens
eliza botto
Verzonden: maandag 15 april 2013 12:36
Aan: [email protected]
Onderwerp: [R] nearest stations in distance matrix
Dear R-user,
Is there a way in R to locate the nearest 5 indices to a station, based on
distances in a distance matrix. In other words i want to have nearest stations
based on the distances in the matrix. The distance matrix, i have, has
dimension 44*44.
Thankyou very much in advance
Elisa
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.