| 1 |
\name{distance_to_nearest} |
| 2 |
|
| 3 |
\alias{distance_to_nearest} |
| 4 |
\alias{distance_to_nearest,Intervals_virtual_or_numeric,Intervals_virtual_or_numeric-method} |
| 5 |
|
| 6 |
\title{Compute distance to nearest position in a set of intervals} |
| 7 |
|
| 8 |
\description{ |
| 9 |
For each point or interval in the \code{from} argument, compute the |
| 10 |
distance to the nearest position in the \code{to} argument. |
| 11 |
} |
| 12 |
|
| 13 |
\usage{ |
| 14 |
\S4method{distance_to_nearest}{Intervals_virtual_or_numeric,Intervals_virtual_or_numeric}(from, to, check_valid = TRUE) |
| 15 |
} |
| 16 |
|
| 17 |
\arguments{ |
| 18 |
|
| 19 |
\item{from}{An object of appropriate type.} |
| 20 |
|
| 21 |
\item{to}{An object of appropriate type.} |
| 22 |
|
| 23 |
\item{check_valid}{ |
| 24 |
Should \code{\link{validObject}} be called before passing to |
| 25 |
compiled code? Also see \code{\link{interval_overlap}}. |
| 26 |
} |
| 27 |
|
| 28 |
} |
| 29 |
|
| 30 |
\value{ |
| 31 |
A vector of distances, with one entry per point or interval in |
| 32 |
\code{from}. Any intervals in \code{from} which are either empty (see |
| 33 |
\code{\link{empty}}) or have \code{NA} endpoints produce a \code{NA} |
| 34 |
result. |
| 35 |
} |
| 36 |
|
| 37 |
\note{ |
| 38 |
This function is now just a wrapper for \code{\link{which_nearest}}. |
| 39 |
} |
| 40 |
|
| 41 |
\seealso{ |
| 42 |
See \code{\link{which_nearest}}, which also returns indices for the |
| 43 |
interval or intervals (in case of ties) at the distance reported. |
| 44 |
} |
| 45 |
|
| 46 |
\examples{ |
| 47 |
# Point to interval |
| 48 |
|
| 49 |
to <- Intervals( c(0,5,3,Inf) ) |
| 50 |
from <- -5:10 |
| 51 |
plot( from, distance_to_nearest( from, to ), type = "l" ) |
| 52 |
segments( to[,1], 1, pmin(to[,2], par("usr")[2]), 1, col = "red" ) |
| 53 |
|
| 54 |
# Interval to interval |
| 55 |
|
| 56 |
from <- Intervals( c(-Inf,-Inf,3.5,-1,1,4) ) |
| 57 |
distance_to_nearest( from, to ) |
| 58 |
} |