Learn R Programming

XVector (version 0.12.0)

slice-methods: Slice an XInteger or XDouble object

Description

The slice methods for XInteger and XDouble objects create views corresponding to the indices where the data are within the specified bounds. The views are returned in a XIntegerViews or XDoubleViews object.

Usage

"slice"(x, lower=-.Machine$integer.max, upper=.Machine$integer.max)
"slice"(x, lower=-.Machine$integer.max, upper=.Machine$integer.max)
"slice"(x, lower=-Inf, upper=Inf, includeLower=TRUE, includeUpper=TRUE, rangesOnly=FALSE)
"slice"(x, lower=-.Machine$double.xmax, upper=.Machine$double.xmax, includeLower=TRUE, includeUpper=TRUE, rangesOnly=FALSE)

Arguments

x
An XInteger or XDouble object. Alternatively, it can also be an integer or numeric vector.
lower, upper
The lower and upper bounds for the slice.
includeLower, includeUpper
Logical indicating whether or not the specified boundary is open or closed.
rangesOnly
A logical indicating whether or not to drop the original data from the output.

Value

An XIntegerViews or XDoubleViews object if rangesOnly=FALSE.An IRanges object if rangesOnly=TRUE.

See Also

Examples

Run this code
vec <- as.integer(c(19, 5, 0, 8, 5))
slice(vec, lower=5, upper=8)

set.seed(0)
vec <- sample(24)
slice(vec, lower=4, upper=16)

Run the code above in your browser using DataLab