santoku - a visual introduction

David Hugh-Jones

04/09/2019

Santoku

A Japanese kitchen knife.

chopping skills

{santoku}

An R package for cutting data.

santoku logo

Some data

##      x   y
## 1 1041 395
## 2 1283 310
## 3 1122 265
## 4 1383 402
## 5  433 331
## 6  538 304

Some data

chop()

chop() is a replacement for base R’s cut() function.

chop()

extend = FALSE

Chopping by a single value

chop_width()

Chops fixed-width intervals

chop_evenly()

Chops groups equal-width intervals

chop_equally()

Chops intervals with an equal number of elements

chop_n()

Chops intervals with a fixed number of elements

  • The last group may have fewer elements

Summary

Chop by: number of elements width
Fixed size chop_n() chop_width()
Fixed no. of groups chop_equally() chop_evenly()

chop_quantiles()

chop_mean_sd()

Quick tables

## x
##   [70, 300)  [300, 600)  [600, 900] (900, 1393] 
##          10          52          44         138
## x
## [-3 sd, -2 sd) [-2 sd, -1 sd)  [-1 sd, 0 sd)   [0 sd, 1 sd)   [1 sd, 2 sd) 
##              5             54             48             80             57

Changing labels

You need one more labels than breaks:

Changing labels

Not sure how many intervals you will have?

Use a lbl_* function.

Changing labels

Not sure how many intervals you will have?

Use a lbl_* function.

Changing labels

Not sure how many intervals you will have?

Use a lbl_* function.

Left-closed and right-closed

Breaks are closed on the left by default.

Left-closed and right-closed

For right-closed breaks use brk_right():

Errors

chopping fail

Errors

Sometimes it’s impossible to create the breaks you want.

## [1] [-Inf, Inf ] [-Inf, Inf ]
## Levels: [-Inf, Inf ]

When the problem comes from the data (x), santoku will try to carry on (e.g. by returning a single interval).

When the problem comes from other parameters, e.g. breaks or extend, santoku will give an error.

## Error: probs contains 1 missing values

Happy chopping!

https://hughjonesd.github.io/santoku

Chopping