Description Usage Arguments Details Value Functions Examples
When seeking the next point in a space, search only among those points that fulfill a given function based on the previously-selected points.
1 2 3 4 5 6 7 8 9 | navigate(.p, ...)
navigate_ordered(x, pi, p1, p2, n)
navigate_ordered_desc(x, pi, p1, p2, n)
navigate_unique(x, pi, p1, p2, n)
navigate_any(x, pi, p1, p2, n)
|
.p |
A function that returns a vector of indices |
... |
Additional arguments passed on to |
x |
The original matrix |
pi |
Indices of already-selected-nodes. During the first step of a
pathway, |
p1 |
Start and end points used in pathway |
p2 |
Start and end points used in pathway |
n |
Number of indices to be found |
The supplied functions navigate_ordered, navigate_unique, and navigate_any can be supplied directly to pathway.
navigate is a generator that takes an arbitrary user-supplied predicate
function that will generate a vector of search indices when given x
, pi
,
p1
, and p2
. This can be useful for drawing a path that, for example, only
moves forward in time, or which introduces a selection probability based on
attributes of the point supplied in another table.
Integer. An integer vector of indices within x
forming the search
space for the next step of the nearest neighbor search.
navigate_ordered
: Select only points with indices following the ones
already selected.
navigate_ordered_desc
: Select only points with indices preceding the ones
already selected.
navigate_unique
: Select only points that have not yet been visited.
navigate_any
: Select any point, even ones that have already been
visited.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | m <- matrix(runif(1000), nrow = 500, ncol = 2)
obs_types <- sample(c("setosa", "versicolor", "virginica"), 500, replace = TRUE)
# A custom predicate function must take the original matrix, the list of
# previously-selected pathway points, along with p1 and p2.
different_species <- function(x, pi, p1, p2, obs_types) {
if (is.null(pi)) {
search_space <- 1:nrow(x)
} else {
# Only search observations that do not have the same species as the immediately previous one.
prev_type <- obs_types[tail(pi, 1)]
search_space <- which(obs_types != prev_type)
}
# Don't forget to exclude p1 and p2
setdiff(search_space, c(p1, p2))
}
p_species <- pathway(m, 2, 11, n = 8, navigator = navigate(different_species, obs_types))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.