R script to calculate bearings and distance between series of points