discretise | R Documentation |
Bins a distribution by specified breakpoints. Left and right endpoints of +/- infinity are implied.
discretise(
distribution,
breakpoints,
midpoints = c("median", "mean", "label"),
values,
closed = c("right", "left")
)
discretize(
distribution,
breakpoints,
midpoints = c("median", "mean", "label"),
values,
closed = c("right", "left")
)
distribution |
Distribution to discretise. |
breakpoints |
Vector of breakpoints separating each bin. |
midpoints, values |
Specify the values associated with each new bin
by either specifying a computation of the |
returns |
A finite distribution with the specified bins. |
NA
breakpoints and values
(if specified) are silently removed.
Will throw an error if the lengths of values
does not end up being
one more than that of breakpoints
.
p1 <- dst_norm(0, 1)
p2 <- discretise(p1, breakpoints = -2:2)
p3 <- discretise(p1, breakpoints = -2:2, midpoints = "mean")
plot(p1, "cdf", from = -3, to = 3)
plot(p2, "cdf", from = -3, to = 3, add = TRUE, col = "blue", n = 1000)
plot(p3, "cdf", from = -3, to = 3, add = TRUE, col = "red", n = 1000)
discretise(dst_exp(0.1), breakpoints = numeric())
dst_norm(0, 1) %>%
slice_left(-2) %>%
slice_right(2) %>%
discretize(-2:2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.