Skip to contents

This function adds a new column zt to the input data.frame, which contains the datetime values in datetime_col shifted so that lights_on_hour becomes the new midnight (00:00:00).

Usage

add_zt(df, datetime_col, lights_on_hour)

Arguments

df

A data.frame

datetime_col

The name of the column containing the datetime values to be shifted

lights_on_hour

A numeric value between 1 and 23 representing the hour at which lights are turned on, and which should become the new midnight (00:00:00)

Value

A dataframe with the new zt column

Examples

df <- data.frame(
  datetime_col = seq(from = as.POSIXct("2023-07-20 00:00:00", tz = "UTC"),
                     to = as.POSIXct("2023-07-21 00:00:00", tz = "UTC"),
                     by = "hour"),
  value = runif(25)
)

lights_on_hour = 6
df <- add_zt(df, datetime_col, lights_on_hour)