clump_date | R Documentation |
This accepts a date, but changes the day. Set/degrade/clump all the days within a month/week to the same day.
clump_month_date( date_detailed, day_of_month=15L )
clump_week_date( date_detailed, day_of_week=2L )
date_detailed |
The |
day_of_month |
The factor label assigned to the missing value. Defaults to |
day_of_week |
The factor label assigned to the missing value. Defaults to |
We use this frequently to set/degrade/clump all the days to the middle of their respective month (ie, the 15th day). The midpoint of a month is usually the most appropriate summary location. It makes graphs more intuitive. Using the midpoint of month can also avoid problems with timezones. A date won't get nudged to a neighboring month accidentally.
An array of Date
values.
A stop
error will be thrown if date_detailed
is not a Date
. day_of_month
must be bounded by [1, 31]
, and
day_of_week
must be bounded by [1, 7]
.
Be careful that if you set a November date the 31st day, the result will be December 1st.
Consequently, we recommend not setting the day to a value after the 28.
The sql equivalent to clump_month_date()
is CAST(convert(char(7), GETDATE(), 126) + '-15' AS date)
.
The sql equivalent to clump_week_date()
is SELECT DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0)
Will Beasley
These functions are gloves around lubridate::day()
and
lubridate::wday()
Essentially the add just error-checking and default values.
library(OuhscMunge)
detailed <- seq.Date(from=as.Date("2011-04-21"), to=as.Date("2011-07-14"), by="day")
clumped_month <- clump_month_date(detailed)
table(clumped_month)
# 2011-04-15 2011-05-15 2011-06-15 2011-07-15
# 10 31 30 14
clumped_week <- clump_week_date(detailed)
table(clumped_week)
# 2011-04-18 2011-04-25 2011-05-02 2011-05-09 2011-05-16 2011-05-23 2011-05-30
# 3 7 7 7 7 7 7
# 2011-06-06 2011-06-13 2011-06-20 2011-06-27 2011-07-04 2011-07-11
# 7 7 7 7 7 5
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.