sl.match.comp: Find First Comparison Match

View source: R/sl.match.comp.R

sl.match.compR Documentation

Find First Comparison Match

Description

A simple function returning the index i of the first element of a vector table for which table[i] COMP x == TRUE, where x is a scalar and COMP is one of a number of comparison operators that can be specified.

Usage

sl.match.comp(x, table, comp.op = "gt", offset = 0)

Arguments

x

a scalar to be compared with the elements of table.

table

a vector whose elements are to be compared with x.

comp.op

a character giving a comparison operator. Must be one of 'gt' ('greater than'; default), 'lt' (less than), 'get' (greater than or equal with), 'let' (less than or equal with), and 'eq' (equal with).

offset

an integer indicating how many indices to skip at the beginning.

Details

Note that the function works with matrices, too, but in an unexpected manner, returning a one-dimensional index.

Value

An integer giving the index of the first element (optionally after skipping a number of elements) for which the comparison is TRUE.

Author(s)

Helge Goessling

Examples

sl.match.comp(x=7.2,table=seq(1,10),comp.op="gt")
## Should return:
## [1] 8

FESOM/spheRlab documentation built on April 6, 2024, 6:52 p.m.