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: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens 
eliza botto
Verzonden: maandag 15 april 2013 12:36
Aan: r-help@r-project.org
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

______________________________________________
R-help@r-project.org 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.

Reply via email to