Skip to content

Instantly share code, notes, and snippets.

@Plaudenslager
Created May 12, 2016 17:42
Show Gist options
  • Save Plaudenslager/d2bd5a2c326b0e53312525d4ab67d45a to your computer and use it in GitHub Desktop.
Save Plaudenslager/d2bd5a2c326b0e53312525d4ab67d45a to your computer and use it in GitHub Desktop.
Group data into date-oriented buckets, e.g. week or month in R
library(dplyr)
# Signup.Date is original date information in Date format
# Signup.Week is beginning date of week that contains Signup.Date
# cut function can take other parameters instead of "weeks": "day", "week", "month", "quarter" and "year"
# adds a column of dates to the dataframe that groups data into week-long buckets
clean_data <- clean_data %>% mutate(Signup.Week = cut(Signup.Date, "weeks"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment