x= rnorm(100)
y = rnorm(100)
dat = cbind(x,y)
newdat = cbind(rnorm(2), rnorm(2))
tree = createIndex(dat)
inds = findKNN(tree, newdat, dat)
ch = rep(1, times=100)
ch[inds[1:5]] = 3
ch[inds[6:10]] = 5
cls = rep("black", times=100)
cls[inds[1:5]] = "red"
cls[inds[6:10]] ="blue"
plot(x,y, pch=ch, col = cls)
abline(v=newdat[1,1], h = newdat[1, 2], col="red")
abline(v=newdat[2,1], h = newdat[2,2], col = "blue")
Run the code above in your browser using DataLab