Learn R Programming

tilingArray (version 1.50.0)

sampleStep: Sampling of ascending numbers to ensure minimal spacing.

Description

Given a vector of ascending numbers and a step width, sample the numbers such that the difference between consecutive numbers is greater than or equal to step.

Usage

sampleStep(x, step)

Arguments

x
Numeric or integer vector.
step
Numeric scalar.

Value

A logical vector of the same length as x, representing the selected subsample.

Details

The simple algorithm works greedily from x[1] to x[length(x)]. First, x[1] is selected. Then, if x[i] is selected, all numbers x[j] with j>i and x[j]-x[i] are dropped. Then, i is set to the smallest j with x[j]-x[i]>=step.

Examples

Run this code
 x   = sort(as.integer(runif(20)*100))
 sel = sampleStep(x, step=10)
 x
 x[sel]

Run the code above in your browser using DataLab