0

So I have my dataset titled WSW and I have done the sunrise and sunset functions to get the sunrise and sunset times from a series of dates which has created a second dataset titled df (see below code)

df <-
  getSunlightTimes(
    date = seq.Date(as.Date("1986-01-01"), as.Date("2020-12-31"), by = 1),
    keep = c("sunrise", "sunriseEnd", "sunset", "sunsetStart"),
    lat = 51.4545,
    lon = 2.5879,
    tz = "UTC"
  )

The second dataset however is HUGE as it has all the sunrise and sunset times from 1986 to 2020! There are only 41 dates with sunrise and sunset times that I need between 1986 and 2020 so I was wondering how do I extract that data without typing all 41 dates manually?

I hope this has made sense?! Thanks!!

New Dev
  • 48,427
  • 12
  • 87
  • 129
Emma_94
  • 1
  • 1
  • 1
    just feed your vector of dates to the sunlighttimes-function. – Wimpel Jun 16 '21 at 17:14
  • Hi Emma_94, would you kindly provide a description of the `WSW` dataset? Also, how do you determine what dates you need? Are they calculated (ex. every other `n` days), or are they a selection of arbitrary dates (ex. `Date` values in a vector). If the latter is the case, then you can take your vector `date_vector` and pass it to `getSunlightTimes()` like so: `getSunlightTimes(date = date_vector, ...)`. – Greg Jun 16 '21 at 17:32
  • Do note that simply typing `??suncalc::getSunlightTimes` will bring up the [documentation](https://cran.r-project.org/web/packages/suncalc/suncalc.pdf) (pg. 7 - 9) for `getSunlightTimes()`, as will hovering over the function call and pressing **F1**. The `date` parameter is described as _"Single or multiple Date. YYYY-MM-DD"_; here _"multiple"_ indicates multiple (`Date`) values within a vector. **If in doubt, check the documentation!** – Greg Jun 16 '21 at 17:44

0 Answers0