I seem to be stuck with what I thought should be a fairly simple task.
I have a data frame (~800,000 rows) with a timestamp (Datetime, also broken down to Date, and Time), and the time of Sunset, Sunrise, Dusk, Dawn, and Night for that specific date (from solar calculations). All columns are currently of class POSIXct.
I want to add a column $Period by assigning each row with a single period as in the following examples:
If Time > Night & < Dawn = “Night”
If Time >= Dawn & < Sunrise = “Dawn”
If Time >= Sunrise & < Sunset = “Day”
I tried a nested ifelse function, but ifelse() messes up the POSIXct format, so comparing times becomes a serious problem.
I also tried other time formats (using chron, lubridate), but can’t seem to hack it.
Help would be very much appreciated.