Creating R function to calculate the distance between two points (x1,y1) and (x2,y2)

Hello y’all,
I can’t seem to figure this out. I have 5 sets of points to calculate. Can someone point me in the right direction to try to create this

Hi @Dallas3726,
Welcome to the RStudio Community Forum.

Your question sounds a lot like "home-work"! You should read the posting guide to this forum, and try to post some code that you have written that attempts to solve your problem (but perhaps fails for some reason that you can't work out).

Here are some steps you could follow:

  1. Create some dummy data in a data.frame that represent your points (hint: 4 columns).
  2. Do some trigonometry calculations on those numbers to find the distances.
  3. When that code is working, convert it into a simple user-defined function.
1 Like

Create a dataframe with your desired points as values.
Then use the functions of R to calculate the distance, below there are instructions.
https://search.r-project.org/CRAN/refmans/raster/html/pointDistance.html

If you need a practical example, you can watch:

Hope this helps.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.