check.range: Utilities for Ranges of Values

View source: R/utilseq.R

check.rangeR Documentation

Utilities for Ranges of Values

Description

These simple functions handle an interval or range of numerical values. check.range(r) checks whether r specifies a range of values, that is, whether r is a vector of length 2 with r[1] <= r[2]. intersect.ranges(r, s) finds the intersection of two ranges r and s. inside.range(x, r) returns a logical vector containing TRUE if the corresponding entry of x falls inside the range r, and FALSE if it does not. check.in.range(x, r) checks whether a single number x falls inside the specified range r. Finally prange(r) produces a character string that represents the range r.

Usage

check.range(r, fatal = TRUE)

check.in.range(x, r, fatal = TRUE)

inside.range(x, r)

intersect.ranges(r, s, fatal = TRUE)

prange(r)

Arguments

r

A numeric vector of length 2 specifying the endpoints of a range of values.

x

Numeric vector of data.

s

A numeric vector of length 2 specifying the endpoints of a range of values.

fatal

Logical value indicating whether to stop with an error message if the data do not pass the check.

Details

check.range checks whether r specifies a range of values, that is, whether r is a vector of length 2 with r[1] <= r[2]. If so, the result is TRUE. If not, then if fatal=TRUE, an error occurs, while if fatal=FALSE the result is FALSE.

intersect.ranges(r, s) finds the intersection of two ranges r and s. If the intersection is non-empty, the result is a numeric vector of length 2. If the intersection is empty, then if fatal=TRUE, an error occurs, while if fatal=FALSE the result is NULL.

inside.range(x, r) returns a logical vector containing TRUE if the corresponding entry of x falls inside the range r, and FALSE if it does not.

check.in.range(x, r) checks whether a single number x falls inside the specified range r. If so, the result is TRUE. If not, then if fatal=TRUE, an error occurs, while if fatal=FALSE the result is FALSE.

Finally prange(r) produces a character string that represents the range r.

Value

The result of check.range, check.in.range and inside.range, is a logical value or logical vector. The result of intersect.ranges is a numerical vector of length 2, or NULL. The result of prange is a character string.

Author(s)

\adrian

Examples

   rr <- c(0, 2)
   ss <- c(1, 3)
   x <- seq(0.5, 3.5, by=1)
   check.range(rr)
   check.range(42, fatal=FALSE)
   inside.range(x, rr)
   intersect.ranges(rr, ss)
   prange(rr)   

spatstat/spatstat.utils documentation built on Aug. 18, 2024, 2:39 p.m.