Skip to content

Instantly share code, notes, and snippets.

@ateucher
Created August 18, 2015 20:58
Show Gist options
  • Save ateucher/7ee9982c10d854631402 to your computer and use it in GitHub Desktop.
Save ateucher/7ee9982c10d854631402 to your computer and use it in GitHub Desktop.
Summarise hourly data by date
library(dplyr)
## Make some mock data for illustration:
date_time <- seq(as.POSIXct("2014-01-01"), as.POSIXct("2015-08-18"), by = "1 hour")
value <- rnorm(length(date_time))
my_data <- data.frame(date_time, value)
# Create a date column (remove time)
my_data$date <- as.Date(my_data$date_time, tz = "Canada/Pacific")
# Group by date and summarise values
my_data_summarized <- group_by(my_data, date) %>%
summarise(daily_mean = mean(value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment