| chop_n | R Documentation |
chop_n() creates intervals containing a fixed number of elements.
chop_n(x, n, ..., close_end = TRUE, tail = "split")
brk_n(n, tail = "split")
tab_n(x, n, ..., tail = "split")
x |
A vector. |
n |
Integer. Number of elements in each interval. |
... |
Passed to |
close_end |
Logical. Close last break at right? (If |
tail |
String. What to do if the final interval has fewer than |
The algorithm guarantees that intervals contain no more than n elements, so
long as there are no duplicates in x and tail = "split". It also
guarantees that intervals contain no fewer than n elements, except possibly
the last interval (or first interval if left is FALSE).
To ensure that all intervals contain at least n elements (so long as there
are at least n elements in x!) set tail = "merge".
If tail = "split" and there are intervals containing duplicates with more
than n elements, a warning is given.
chop_* functions return a factor of the same length as x.
brk_* functions return a function to create breaks.
tab_* functions return a contingency table().
Other chopping functions:
chop(),
chop_equally(),
chop_evenly(),
chop_fn(),
chop_mean_sd(),
chop_proportions(),
chop_quantiles(),
chop_width(),
fillet()
chop_n(1:10, 5)
chop_n(1:5, 2)
chop_n(1:5, 2, tail = "merge")
# too many duplicates
x <- rep(1:2, each = 3)
chop_n(x, 2)
tab_n(1:10, 5)
# fewer elements in one group
tab_n(1:10, 4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.