Slice
A slice is an operation or function that selects and returns a portion of an ordered data structure by positions, indices, or ranges.
The Well-Grounded Rubyist, Fourth Edition
Array#slice is a Ruby Array method that retrieves elements specified by an index, an index and length, or a range.
- How it is used
- Retrieves array elements as a named alternative to `Array#[]` during collection manipulation.
- How deep it goes
- Explains single-index, index-and-length, and range retrieval, but does not establish out-of-range behavior.
- Examples
- Uses a color array to show two-element and range retrieval alongside `[]` assignment.
- What you can do after
- Apply it via Ruby’s `Array#slice` to retrieve one element or a contiguous group without removing it.
Read how The Well-Grounded Rubyist, Fourth Edition explains slice →
Statistics Slam Dunk
The dplyr slice() function selects rows from a tabular object by their positions, including positions computed within groups.
- How it is used
- Selects rows by position within grouped or ungrouped tabular data.
- How deep it goes
- Demonstrates grouped deletion, maximum-row selection, and row preservation, but does not detail broader positional-selection variants.
- Examples
- Uses Julius Randle free throws and year-by-year NBA scoring leaders as worked row-selection examples.
- What you can do after
- Apply it via dplyr to remove grouped rows or retain complete records meeting grouped positional criteria.
Related concepts
- arrayproduces · An array is an indexed, ordered collection of elements arranged in one or more dimensions, with elements accessed by position.
- shallow copyproduces · A shallow copy duplicates a data structure’s outer container while retaining references to its nested values rather than copying them recursively.
- []equivalent to · [] is a Ruby String method that retrieves characters or substrings using indexes, ranges, strings, or regular expressions.
- group_by()used by · group_by() assigns grouping variables to tabular data so subsequent operations can be performed separately within each group.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

