x_hour <- seq(lubridate::ymd_hms("20160302 000000"),
by = "hour",
length.out = 200
)
some_df <- data.frame(x_hour = x_hour)
thicken(some_df, "week")
thicken(some_df, "month")
thicken(some_df, "day", start_val = lubridate::ymd_hms("20160301 120000"))
x_df <- data.frame(
x = seq(lubridate::ymd(20130101), by = "day", length.out = 1000) |>
sample(500),
y = runif(500, 10, 50) |> round()
) |>
dplyr::arrange(x)
# get the max per month
x_df |>
thicken("month") |>
dplyr::group_by(x_month) |>
dplyr::summarise(y_max = max(y))
# get the average per week, but you want your week to start on Mondays
# instead of Sundays
x_df |>
thicken("week",
start_val = closest_weekday(x_df$x, 2)
) |>
dplyr::group_by(x_week) |>
dplyr::summarise(y_avg = mean(y))
# rounding up instead of down
x <- data.frame(dt = lubridate::ymd_hms(
"20171021 160000",
"20171021 163100"
))
thicken(x, interval = "hour", rounding = "up")
thicken(x, interval = "hour", rounding = "up", ties_to_earlier = TRUE)
Run the code above in your browser using DataLab