| sl.segment | R Documentation |
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.
sl.segment(logivec, extend = FALSE, first.only = FALSE, return.segments = TRUE)
logivec |
a vector of logical values. |
extend |
a logical value indicating whether indices/segments shall be extended to contain the neighbouring |
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. |
This function is used internally by sl.plot.polygon when polygons need to be truncated.
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.
Helge Goessling
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.