stretches: finds first non-zero stretch of elements

Description Usage Arguments Examples

View source: R/utils.R

Description

returns the position of the first non-zero stretch of elements. gaps shorter than 'gap' do not interrupt a stretch.

Usage

1
stretches(input, gap, what, zero.surrounded)

Arguments

input

a vector of numerical values.

gap

the smallest sequence of NA or zeroes that will interrupt a stretch. defaults to 1 (sequences must be contiguous).

what

character; if '"start"', finds where stretches start. if '"end"', finds where stretches end. defaults to '"start"'.

zero.surrounded

logical; if 'TRUE', assumes infinite zeroes leading and trailing the input vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
input <- rep(0, 90)
input[6:10] <- NA
input[12:19] <- 1       # contiguous data
input[50+(0:3)*2] <- 2  # data with 1-gaps
input[70+(0:3)*3] <- 3  # data with 2-gaps

stretches(input)
# [1] 12 50 52 54 56 70 73 76 79
stretches(input, 2)
# [1] 12 50 70 73 76 79
stretches(input, 3)
# [1] 12 50 70

delftfews documentation built on May 2, 2019, 4:48 p.m.