sl.segment: Segment Logical Vector

sl.segmentR Documentation

Segment Logical Vector

Description

Find contiguous segments of TRUE values in a logical vector. Returns either start and end indices of (one or more) segments, or one or more vectors of segment indices.

Usage

sl.segment(logivec, extend = FALSE, first.only = FALSE, return.segments = TRUE)

Arguments

logivec

a vector of logical values.

extend

a logical value indicating whether indices/segments shall be extended to contain the neighbouring FALSE values.

first.only

a logical value indicating whether only the first index pair or segment shall be returned.

return.segments

a logical value indicating whether, instead of start and end indices, complete segment index vectors shall be returned.

Details

This function is used internally by sl.plot.polygon when polygons need to be truncated.

Value

If return.segments=TRUE: a vector of indices corresponding to a segment of contiguous TRUE values in logivec if only one segment is contained or if first.only=TRUE, or otherwise an (unnamed) list of such vectors.

If return.segments=FALSE: a list with the elements start and end, each of which are scalars or vectors of the same length giving the start and end indices of segments of contiguous TRUE values in logivec.

Author(s)

Helge Goessling

Examples

sl.segment(c(rep(TRUE,3),rep(FALSE,5),rep(TRUE,2),rep(FALSE,7),rep(TRUE,1)),extend=TRUE,first.only=FALSE,return.segments=TRUE)
## Should return:
## [[1]]
## [1]  8  9 10 11
## 
## [[2]]
## [1] 17 18  1  2  3  4

sl.segment(c(rep(TRUE,3),rep(FALSE,5),rep(TRUE,2),rep(FALSE,7),rep(TRUE,1)),extend=FALSE,first.only=FALSE,return.segments=FALSE)
## Should return:
## $start
## [1]  9 18
## 
## $end
## [1] 10  3

helgegoessling/spheRlab documentation built on March 8, 2024, 7:54 p.m.