  For example:

x = runif(100)
y = runif(100)
f = factor(sample(c("M","F","U"),size=100,replace=TRUE))
dmat = as.matrix(dist(cbind(x,y)))
diag(dmat) = Inf
nrnbr = apply(dmat,1,which.min)
nrclass = f[nrnbr]
table(f,nrclass)

	[[alternative HTML version deleted]]

