-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
80 lines (59 loc) · 1.47 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# A Class for Week Numbers
<!-- badges: start -->
[![R build status](https://github.com/hmalmedal/weeknumber/workflows/R-CMD-check/badge.svg)](https://github.com/hmalmedal/weeknumber/actions)
<!-- badges: end -->
A class for week numbers, according to ISO 8601.
## Documentation
* https://hmalmedal.github.io/weeknumber/
## Installation
Install from [GitHub](https://github.com/hmalmedal/weeknumber):
```{r gh-installation, eval = FALSE}
remotes::install_github("hmalmedal/weeknumber")
```
## Examples
Coercion to the week number class:
```{r coercion, message=FALSE}
library(weeknumber)
as_weeknumber(c(-1:1, 51:52, NA))
as_weeknumber("2000-W01")
as_weeknumber(as.Date("2000-12-28"))
```
Make week number object from year and week:
```{r make_weeknumber}
make_weeknumber(2000:2001, 4:5)
make_weeknumber(2019:2020, 53)
```
Get year and week number from an object:
```{r year_week}
x <- as_weeknumber(c(-1:1, 51:52, NA))
year_week(x)
```
Print a tibble:
```{r tibble}
set.seed(0)
library(tibble)
d <- tibble(
x = seq(as_weeknumber("2000-W01"), as_weeknumber("2000-W09")),
y = cumsum(rnorm(length(x)))
)
print(d)
```
Plot with week number scale:
```{r plot}
library(ggplot2)
p <- ggplot(d, aes(x, y)) +
geom_line()
print(p)
```