weeks: Show ceiling / floor days of a week

Description Usage Arguments Value Weekend See Also Examples

Description

Takes vector of dates and outputs floor or ceiling date of the respective week. The end of week can be defined. The output can be used e.g. for zoo aggregation. This is inspired tremendously by Stackoverflow users G.Grothendieck and Joshua Ulrich

Usage

1
2
3
week_ceiling(x, weekend = NULL)

week_floor(x, weekend = NULL)

Arguments

x

Vector of dates

weekend

what's the end of week? Default to Sunday

Value

vector of dates. can be used in aggregations, e.g. with zoo.aggregate

Weekend

weekday names in locale (!!) If you want to pass in a different locale, use index instead. Also accepts index 0:6 (d0 = Sunday, d1 = Monday,..., d6 = Saturday)

See Also

https://stackoverflow.com/a/4351626/7941188 and https://stackoverflow.com/a/16193667/7941188

Examples

1
2
3
4
5
week_ceiling(as.Date("2021-03-24"))
week_ceiling(as.Date("2021-03-24"), weekend = "friday")
week_ceiling(as.Date("2021-03-24"), weekend = 1) # 1 = Monday
week_floor(as.Date("2021-03-24"))
week_floor(as.Date("2021-03-24"), weekend = 5) # 5 = Friday

tjebo/tjebtools documentation built on Nov. 15, 2021, 11:21 p.m.