I have a data frame generated from computing nearest neighbor (K=2) using the RANN package. I would like to transform this data into a matrix with values of 0,1,2 for each cell with 0 = not neighbor, 1=nearest neighbor, 2=2nd nearest neighbor.
The data frame has two columns, the first column is the ID of the 1st NN, the second column is the ID of the 2nd NN. The rows correspond to the ID of the point from which the NN were calculated.
Is there an existing routine to easily to this sort of transformation?
Thanks