I have a data frame of x-y coordinates and I would like to calculate distances between consecutive points. My issue is that I don't know how to calculate a new column using multiple points from another column.
I know how to calculate a new column like covered here: Creating a new column to a data frame using a formula from another variable
However, the distance formula requires two values from the same column to calculate a value (distance = sqrt((x2-x1)^2+(y2-y1)^2)). How do I specify x1 vs x2 and y1 vs y2 if I only have a single column for x and y? Also, will there be any issues for the first point since it doesn't have a point before it? (i.e. there will be an empty distance cell - is that an issue?)
I know I can do this in Excel fairly easily, but I have a lot of different datasets that need the same treatment so I'd like to automate it in R.