Learn R Programming

lambda.tools (version 1.0.9)

range_for: Find contiguous ranges of a given value within a sequence

Description

Identify the index ranges for a given value in a sequence and return the minimum and maximum values of the ranges.

Arguments

target
A value to find in x
x
A vector

Value

A data.frame where each row specifies the end points of a contiguous range that contains the target value

Usage

range_for(target, x)

Examples

Run this code
# Find all contiguous ranges containing 2
x <- sample(c(1,2,2,2,3,4), 20, replace=TRUE)
range_for(2,x) 

Run the code above in your browser using DataLab