I understand there are several tools out there that can help me accomplish my goal, but I think I'm running into more of a conceptual roadblock. I've tried to implement a fully reproducible example in seeking assistance.
The situation: I have two point shapefiles, one with 5 points (fewpoints.shp) and the other with many points ~100 (manypoints.shp). For each of the many points, I'd like to find the distance to each of the 5 points, such that the final df looks like:
ID DistPnt1 DistPnt2 DistPnt3 DistPnt4 DistPnt5
I've been able to generate a distance matrix and melt it into a dataframe, but I'm having trouble understanding how I'm supposed to retain the original ids such that I can merge them back onto manypoints.shp.
MN <- us_states(resolution="low", states = "MN")
MNspdf <- as_Spatial(MN)
smallpoints <-spsample(MNspdf , 5, type = "random")
manypoints <-spsample(MNspdf , 100, type = "random")
Is it safe to assume that each row corresponds to the original rows of the manypoints.shp? Am I missing something?