R package to zip together sorted arrays
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R
docker
m4
man-roxygen
man
rpkg_make @ 569dee6
src
tests
.Rbuildignore
.gitignore
.gitmodules
.travis.yml
ChangeLog
DESCRIPTION
Makefile
NAMESPACE
README.Rmd
README.md

README.md

zipper

Build Status codecov.io RCpp is true

it zips the index in the basket!

Zips two sorted arrays into each other. That's it. Not for CRAN.

-- Steven E. Pav, shabbychef@gmail.com

Installation

This package can be installed via drat, or from github:

# via drat:
if (require(drat)) {
    drat:::add("shabbychef")
    install.packages("zipper")
}
# get snapshot from github (may be buggy)
if (require(devtools)) {
    install_github("shabbychef/zipper")
}

What?

Suppose you have two sorted arrays and need to align them. That's a zip operation. Back when I worked with time series (in Matlab), a zip operation was at the base of the 'look back' join operation. That is all this package does:

require(zipper)
set.seed(1234)
reference_x <- sort(rnorm(10000))
lookup_y <- sort(rnorm(100))
idxs <- zipper::zip_le(reference_x, lookup_y)
head(idxs)
## [1] 104 106 119 126 155 165
# compare to this slow version:
altv <- rep(NA_integer_, length(lookup_y))
for (iii in seq_along(lookup_y)) {
    altv[iii] <- sum(reference_x <= lookup_y[iii])
}
stopifnot(all.equal(altv, idxs))