x_hour <- seq(lubridate::ymd_hms('20160302 000000'), by = 'hour',
length.out = 200)
some_df <- data.frame(x_hour = x_hour)
thicken(some_df)
thicken(some_df, 'month')
thicken(some_df, start_val = lubridate::ymd_hms('20160301 120000'))
library(dplyr)
x_df <- data.frame(
x = seq(lubridate::ymd(20130101), by = 'day', length.out = 1000) %>%
sample(500),
y = runif(500, 10, 50) %>% round) %>%
arrange(x)
# get the max per month
x_df %>% thicken('month') %>% group_by(x_month) %>%
summarise(y_max = max(y))
# get the average per week, but you want your week to start on Mondays
# instead of Sundays
min_x <- x_df$x %>% min
weekdays(min_x)
x_df %>% thicken(start_val = min_x - 1) %>%
group_by(x_week) %>% summarise(y_avg = mean(y))
Run the code above in your browser using DataLab