I have a table with some vessel GPS data. Just like
ID POSTIME LON LAT SPEED AZIMUTH
1 2015-12-31 23:56:15 123.4003 32.39449 5.2 145
2 2015-12-31 23:56:53 123.3982 32.39487 5.2 138
3 2015-12-31 23:59:53 123.3884 32.39625 5.3 138
4 2016-01-01 00:01:19 123.3836 32.39702 5.2 146
5 2016-01-01 00:02:58 123.3788 32.39915 5.1 154
6 2016-01-01 00:06:41 123.3708 32.40391 5.1 157
And I want to calculate the distance, time difference and angle difference of the ship at each sample point. I have written a function point.distance for calculating distance by lon and lat of different points, just like
point.distance <- function(lon1,lat1,lon2,lat2)
lon1/2 and lat1/2 stands for different points
also with a point.angle function to calculate angle difference
point.angle <- function(lon1,lat1,lon2,lat2,lon3,lat3)
I know how to use functions on 2 individual points, but how to apply the functions to all the rows and add the results to new columns in order to further analyze?
I hope my results might be like
ID POSTIME LON LAT SPEED AZIMUTH DISTANCE TD AD
1 2015-12-31 23:56:15 123.4003 32.39449 5.2 145 NA 00:00:38 -7
2 2015-12-31 23:56:53 123.3982 32.39487 5.2 138 201.873 00:03:00 0
3 2015-12-31 23:59:53 123.3884 32.39625 5.3 138 ... ... ...
4 2016-01-01 00:01:19 123.3836 32.39702 5.2 146 ... ... ...
Is there any package or function will act like this? Or should I just save the results in different vectors and then write to the xlsx file at last?