For each value in a numeric vector, return the closest match from a vector of candidate values.
snap(x, rule = 1, left = TRUE, ...)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.
If length of x is zero, it is returned unmodified. If length of rule is zero, value is all NA.