zipsorted: Zip sorted arrays against each other

Description Usage Arguments Details Value Note Author(s) Examples

Description

Given two sorted arrays, x and y, find indices L that ‘zips’ the two together.

Usage

1
2
3
zip_le(sortx, looky)

zip_lt(sortx, looky)

Arguments

sortx

a sorted array of ‘reference’ values.

looky

a sorted array of values whose place among sortx is to be found.

Details

For example, for zip_le, we find the array L of the same length as y such that there are exactly L_i elements of x less than or equal to y_i.

Value

a vector, filled out as follows:

zip_le

Returns the vector L such that there are exactly L_i elements of x less than or equal to y_i.

zip_lt

Returns the vector L such that there are exactly L_i elements of x less than y_i.

Note

Returns zero when there are none, as expected.

it would be better if this code supported mixed types of sortx and looky.

Author(s)

Steven E. Pav shabbychef@gmail.com

Examples

1
2
3
4
5
6
7
8
9
set.seed(1234)
x <- sort(rnorm(1e5))
y <- sort(rnorm(1e2))
idx1 <- zip_le(x,y)
# slow way, should give the same answer
uther <- rep(NA,length(y))
for (iii in 1:length(y)) {
  uther[iii] <- sum(x <= y[iii])
}

shabbychef/zipper documentation built on April 5, 2021, 7:31 p.m.