num_leq_sorted: Less-Than-Or-Equal Comparison of Sorted Vectors

Description Usage Arguments Value Note See Also Examples

View source: R/C_interfaces.R

Description

For two sorted numeric vectors a and b, for each element a[i] determine the number of elements in b that are less than or equal (leq) to this value.

Usage

1
num_leq_sorted(a, b, tolerance = 0)

Arguments

a

a sorted, i.e. non-decreasing, vector of numbers.

b

a sorted, i.e. non-decreasing, vector of numbers.

tolerance

a non-negative number, indicating the tolerance for numerical noise.

Value

An integer vector of same length as a.

Note

Equivalently, because the input vectors are sorted, for each element a[i] determine the maximum index j with b[j] <= a[i].

See Also

num_less_sorted for a less-than comparison of two sorted vectors.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# The second vector has
# -) 0 elements leq (less-than-or-equal) -3
# -) 2 elements leq 1
# -) 2 elements leq 3
# -) 3 elements leq 5
# -) 3 elements leq 7
num_leq_sorted(c(-3, 1, 3, 5, 7), c(0, 1, 4, 9, 16))

# Numerical noise < tolerance has no effect
num_leq_sorted(1, 0:2, tolerance=1e-12)
num_leq_sorted(1 - 1e-13, 0:2, tolerance=1e-12)
num_leq_sorted(1 + 1e-13, 0:2, tolerance=1e-12)

# Trivial cases
num_leq_sorted(1:5, 1:5)
num_leq_sorted(c(), 1:5)
num_leq_sorted(1:5, c())

andreas50/uts documentation built on April 8, 2021, 10:03 a.m.