Description Usage Arguments Details Value Examples
backtrace_values()
traces a chain of entries with the same value backwards through a vector.
1 | backtrace_values(x, backtrace_val, starts)
|
x |
A vector in which a value is to be traced backwards. |
backtrace_val |
The value to be traced. |
starts |
An integer vector of the same length as |
Supplied with a vector starts
of starting points (e.g. as returned by
detect_transitions()
), this function traces a value backtrace_val
backwards within a vector x
. This defines a chain of entries whose value is
equal to the traced value. The output may be coerced to a logical vector and
used for indexing the original sequence (see examples).
An integer vector of the same length as x
, with values of 1
if the
entry belongs to a chain, and 0
otherwise.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # Determine the start of a "Dead" to "Alive" transition for a sequence of
# mortality measurements
x <- c("Alive", "Almost dead", "Dead", "Dead", "Dead", "Alive", "Dead",
"Dead", "Alive", "Dead", "Cut and Resprout", "Dead", "Alive")
da_starts <- detect_transitions(x, c("Dead", "Alive"))
# Backtrace all values equal to "Dead"
backtrace_values(x, "Dead", da_starts)
# Extract positions of the traced values
trace <- as.logical(backtrace_values(x, "Dead", da_starts))
which(trace)
x[trace]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.