snap: Coerce Values to Nearest of Candidates

Description Usage Arguments Details Value Note Author(s) References See Also Examples

Description

For each value in a numeric vector, return the closest match from a vector of candidate values.

Usage

1
snap(x, rule = 1, left = TRUE, ...)

Arguments

x

numeric

rule

a vector of (finite numeric) candidates, or a single value giving candidate interval on the real number line

left

whether to return the lesser of two equidistant candidates

...

ignored

Details

If rule is scalar, it must be positive; a rule will be constructed as a sequence of rule-spaced values that includes zero and includes values at least as extreme as the extremes of x. In some sense, this function is the complement to cut: whereas in cut one specifies the "breaks", with snap one specifies a set of "attractors" (breaks are the implied midpoints); both functions map their primary argument to a (possibly) smaller set of values.

Value

numeric

Note

If length of x is zero, it is returned unmodified. If length of rule is zero, value is all NA.

Author(s)

Tim Bergsma

References

http://metrumrg.googlecode.com

See Also

Examples

1
2
3
4
5
6
7
snap(c(0.0, 1.0, 1.2, 2.0, 2.9, 3))
snap(-10:10, 0.3)
xyplot(conc~Time,data=Theoph,groups=Subject)
times <- c(0,.25,.5,1,2,4,5,7,9,12,24)
xyplot(conc~snap(Time,times),data=Theoph,groups=Subject)
snap(c(3,NA,5), c(2,4,6))
snap(c(3,NA,5), numeric(0))

anniejw6/metrumrg documentation built on May 10, 2019, 11:50 a.m.