-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.Rmd
112 lines (75 loc) · 2.42 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# santoku <img src="man/figures/logo.png" align="right" alt="santoku logo" width="120" />
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/santoku)](https://CRAN.R-project.org/package=santoku)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![CRAN Downloads Per Month](http://cranlogs.r-pkg.org/badges/santoku)](https://CRAN.R-project.org/package=santoku)
[![R-universe](https://hughjonesd.r-universe.dev/badges/santoku)](https://hughjonesd.r-universe.dev/santoku)
[![R-CMD-check](https://github.com/hughjonesd/santoku/workflows/R-CMD-check/badge.svg)](https://github.com/hughjonesd/santoku/actions)
[![Codecov test coverage](https://codecov.io/gh/hughjonesd/santoku/branch/master/graph/badge.svg)](https://app.codecov.io/gh/hughjonesd/santoku?branch=master)
<!-- badges: end -->
santoku is a versatile cutting tool for R. It provides `chop()`, a replacement
for `base::cut()`.
## Installation
Install from [r-universe](https://r-universe.dev):
``` r
install.packages("santoku", repos = c("https://hughjonesd.r-universe.dev",
"https://cloud.r-project.org"))
```
Or from CRAN:
``` r
install.packages("santoku")
```
Or get the development version from github:
``` r
# install.packages("remotes")
remotes::install_github("hughjonesd/santoku")
```
```{r, child = 'advantages.Rmd'}
```
## Examples
```{r}
library(santoku)
```
`chop` returns a factor:
```{r}
chop(1:5, c(2, 4))
```
Include a number twice to match it exactly:
```{r}
chop(1:5, c(2, 2, 4))
```
Use names in breaks for labels:
```{r}
chop(1:5, c(Low = 1, Mid = 2, High = 4))
```
Or use `lbl_*` functions:
```{r}
chop(1:5, c(2, 4), labels = lbl_dash())
```
Chop into fixed-width intervals:
```{r}
chop_width(runif(10), 0.1)
```
Or into fixed-size groups:
```{r}
chop_n(1:10, 5)
```
Chop dates by calendar month, then tabulate:
```{r}
library(lubridate)
dates <- as.Date("2021-12-31") + 1:90
tab_width(dates, months(1), labels = lbl_discrete(fmt = "%d %b"))
```
For more information, see the [vignette](https://hughjonesd.github.io/santoku/articles/santoku.html).