Sorry about that..
At the begginning I just had my station with the sampling date and time
df <- tribble(
~station, ~sampling_date, ~sampling_time, ~lat, ~lon
"A1", "2021-07-21", "11:18:32", 55.5, -58.9
"A2", "2021-10-17", "12:08:14", 60.5, -61.3
"A3", "2021-09-05", "20:23:45", 66.8, -58.8
"A4", "2021-10-03", "06:31:24", 67.5, -63.7
"A5", "2021-07-26", "01:30:55", 66.8, -58.8)
So to have my sunrise/sunset I did this :
start.date = "20210721"; end.date = "20211017"
Dates <- seq(ymd(start.date),ymd(end.date), by = "days")
sun_df <- expand.grid(Dates = Dates, Station =df$Station) %>%
left_join(df) %>%
group_by(Station, Dates, lat, lon) %>%
mutate(sunrise = getSunlightTimes(Dates,lat,lon,tz = "MST")$sunrise,
sunset = getSunlightTimes(Dates,lat,lon,tz = "MST")$sunset)
With this code, I have a big df with the sunrise/sunset data since start.date from end.date
With a filter I just select my dates according to my station from my df to have this :
sun_df <- tribble(
~station, ~sampling_date, ~sampling_time, ~lat, ~lon, ~sunrise, ~sunset
"A1", "2021-07-21", "11:18:32", 55.5, -58.9, 2021-07-21 00:44:31, 2021-07-21 17:22:04
"A2", "2021-10-17", "12:08:14", 60.5, -61.3, 2021-10-17 03:31:38, 2021-10-17 13:52:47
"A3", "2021-09-05", "20:23:45", 66.8, -58.8, 2021-09-05 02:10:29, 2021-09-05 15:41:20
"A4", "2021-10-03", "06:31:24", 67.5, -63.7, 2021-10-03 03:03:50, 2021-10-03 14:28:02
"A5", "2021-07-26", "01:30:55", 66.8, -58.8, 2021-07-26 00:52:58, 2021-07-26 17:13:54)
After I just applied your code but I have the mistake I shown you..