RE: [R] Minimum distance

From: BXC (Bendix Carstensen) <bxc_at_steno.dk>
Date: Mon 18 Apr 2005 - 10:45:58 EST


> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of
> Williams, Michael
> Sent: Monday, April 18, 2005 1:58 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Minimum distance
>
>
> G'day, I have a matrix 20000 x 500 populated with all the
> distances between a list of airports and a list of towers.
> What I'm having trouble doing is finding the closest airport
> to each tower, Any help would be greatly appreciated.

Try:

( M <- matrix( rnorm( 24 ), 8, 3 ) )
rownames( M ) <- 1:8
( wh <- sweep( M, 2, apply( M, 2, min ), "==" ) ) rownames(M)[ row( wh )[wh] ]

It works in finite time even with M of 20000 by 500 but it breaks down if there is more than one minimum per column.

Bendix Carstensen



Bendix Carstensen
Senior Statistician
Steno Diabetes Center
Niels Steensens Vej 2
DK-2820 Gentofte
Denmark
tel: +45 44 43 87 38
mob: +45 30 75 87 38
fax: +45 44 43 07 06

bxc@steno.dk
www.biostat.ku.dk/~bxc

>
> Regards,
> Michael Williams
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read
> the posting guide! http://www.R-project.org/posting-guide.html
>


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Apr 18 13:46:18 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:15 EST