If I have a dataframe like this:
ID GroupID X Y
1 a 772.7778 226.5
1 a 806.5645 35.3871
1 a 925.5714 300.9286
1 b 708.0909 165.5455
1 b 630.8235 167.4118
2 a 555.3333 151.875
2 a 732.8947 462.3158
Here is the result I want to have:
ID GroupID X Y Distance
1 a 772.7778 226.5 NA
1 a 806.5645 35.3871 dist between((772.7778,226.5),(806.5645,35.3871))
1 a 925.5714 300.9286 dist between((925.5714,300.9286),(806.5645,35.3871))
1 b 708.0909 165.5455 NA
1 b 630.8235 167.4118 dist between((708.0909,165.5455),(630.8235,167.4118))
2 a 555.3333 151.875 NA
2 a 732.8947 462.3158 dist between((732.8947,462.3158),(555.3333,151.875))
Basically is the distance within ID and GroupID. NA here means in each subgroup (e.g. ID=1; GroupID=a) the first distance is NA. Is there anyone can help me? Thanks!!!