Description Arguments Value Usage Details Author(s) Examples
A sequence can be sliced using an explicit pivot point or by using a logical expression.
x |
An indexable data structure, typically a vector |
pivot |
The index of the pivot point in x |
inclusive |
Whether to include the pivot point in the second sub-sequence |
expression |
A logical expression |
A list containing two sub-sequences or sub-matrices
slice(x, pivot, inclusive=FALSE)
slice(x, expression)
This function splits a sequence into two adjacent sub-sequences at a pivot point or based on a logical expression. If a pivot point is chosen, then the inclusive parameter determines whether the value associated with the pivot should be included in both sub-sequences. If FALSE, then the indices of the sub-sequences will have the form [1, pivot], [pivot + 1, n], where n = |x|. If inclusive is TRUE, then the sub-sequences have indices of [1, pivot], [pivot, n]. Obviously the pivot must be an element of the set of indices of x.
An alternative construction is to use an expression to define a slice point. The first sub-sequence corresponds to the values where the expression evaluated to TRUE, while the second sequence corresponds to values when the expression evaluated to FALSE.
In two dimensions only the first variant of this function is defined, as it cannot be guaranteed that a regular matrix will be generated using an arbitrary expression.
Brian Lee Yung Rowe
1 2 3 4 5 6 7 8 9 10 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.