[R] Nearest neighbour in a matrix
R. Michael Weylandt <michael.weylandt@gmail.com>
michael.weylandt at gmail.com
Tue Sep 27 03:00:25 CEST 2011
There's a general no homework policy on this list, but if you use apropos() with some fairly intuitive search terms the problem won't be hard at all once you hit the 'magic' function. You also might want to look at "?apply". After that, ask your TA...
Sorry we couldn't be more help,
Michael Weylandt
On Sep 26, 2011, at 7:56 PM, Spartina <lea_olsen at yahoo.ca> wrote:
> Hello all,
>
> I am brand new to R and doing an exercise for a class. I need to find the
> nearest neighbour for points in the following matrix:
>
>> DistanceMatrix
> x1 x2 x3 x4 x5
> [1,] 0.000000 2.828427 1.581139 2.236068 2.000000
> [2,] 2.828427 0.000000 1.581139 4.123106 2.000000
> [3,] 1.581139 1.581139 0.000000 2.549510 2.121320
> [4,] 2.236068 4.123106 2.549510 0.000000 4.123106
> [5,] 2.000000 2.000000 2.121320 4.123106 0.000000
>
> I am not sure how to go about this as my knowledge of R functions and syntax
> is very basic.
>
> Is there a way of going at it using the pmin function? Otherwise what would
> be a simple way of going about it?
>
> Sorry for posting such a basic question! I've looked at the help pages and
> other forums on the web but am truly stuck here.
>
> Thanks in advance for your help...
>
> Léa
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Nearest-neighbour-in-a-matrix-tp3845747p3845747.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list