logic: Extended logical operators

logicR Documentation

Extended logical operators

Description

Extended binary operators for easy subsetting.

Usage

x %~% target

Similar(x, target, tol = Inf)

Arguments

x, target

numeric vectors

tol

tolerance for similarity

Details

%~% can be thought as a "similar" operator. It's a fuzzy version of %in% in that returns TRUE for the element of x which is the (first) closest to any element of target.

Similar is a functional version of %~% that also has a tol parameter that indicates the maximum allowed tolerance.

Value

A logical vector of the same length of x.

See Also

Other utilities: Anomaly(), JumpBy(), Mag(), Percentile()

Examples

set.seed(198)
x <- rnorm(100)
x[x %~% c(0.3, 0.5, 1)]

##--not run
## Practical use case: vertical cross-section at
## approximately 36W between 50S and 50N.
# cross.lon <- -34 + 360
# library(ggplot2)
# library(data.table)
# ggplot(temperature[lon %~% cross.lon & lat %between% c(-50, 50)],
#        aes(lat, lev)) +
#     geom_contour(aes(z = air))


wStockhausen/wtsGIS documentation built on Aug. 23, 2023, 2:31 a.m.