I've got a distance matrix between examples. I want to cluster them into m clusters with a nearest neighbor algorithm which works like this:
1. Set i = 1 and k = 1. Assign example x_1 to cluster C_1.
2. Set i = i + 1. Find nearest neighbour of x_i
among the patterns already assigned to clusters.
Let d_n denote the distance from x_i to its nearest neighbour.
Suppose the nearest neighbour is in cluster n.
3. If d_n less than or equal to t then assign x_i to C_n where t is the
threshold specified by the user. Otherwise set k = k+1 and assign x_i to a
new cluster C_k.
How could I adapt this algorithm so I could specify how many clusters I want?
Is anybody aware of an existing R implementation of nearest neighbour clustering?