[R] nearest stations in distance matrix

Rolf Turner rolf.turner at xtra.co.nz
Tue Apr 16 00:50:25 CEST 2013


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



More information about the R-help mailing list