I work in fisheries oceanography. For most of my career, we have used excel to calculate our station run times. Linearly this goes as follows:
We depart from port : arrive at the first station: sample: depart from first station: repeat
Knowing how much we can time-wise (sampling time and running to the next station) is vital for us to get a general idea of how much we can do over a given area.
I've been trying to recreate the spreadsheet we use in r, hopefully to create a Shiny app one day that will be much easier to use. Here's my issue:
The uploaded image shows all the necessary columns of a larger data frame to calculate Departure and Arrival times.
Below is the code used to calculate both Departure and Arrival times. "Dp_Date" is a datetime variable used for your initial departure date (see in screeenshot). "Station == 0" is the port your departing from. I didn't include all of the Lat/Lon data, as it's not part of the question.
SRTdata <- SRTdata %>% mutate(Depart_DT = lubridate::as_datetime(if_else(Station == 0,as.character(Dp_Date),""))) %>%
mutate(Arrival_DT = lag(Depart_DT) + (Steam_T)) %>%
mutate(Depart_DT = Arrival_DT + Station_Time)
Where I'm stumped is how to calculate future Departure and Arrival times as they are based on previous calculations of each other. I think I could do this via purrr:accumulate or purrr::map_df, but I'm stumped. This shouldn't be this difficult.
Thank you for your help.