liveBook · Manning

Slice

A slice is an operation or function that selects and returns a portion of an ordered data structure by positions, indices, or ranges.

How 2 Manning books explain it

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.

Read how Statistics Slam Dunk explains slice →

Related concepts

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.