Description Usage Arguments Details Value Examples
detect_transitions
detects transitions between values in a vector.
1 | detect_transitions(x, transition)
|
x |
A vector in which transitions are to be detected. |
transition |
A vector of length 2, specifying the first and second value of the transition. |
This function is intended to be a helper function to quickly detect transitions in a sequence of values that are assumed to be erroneous. 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
. The start (i.e. first
value) of a transition is 1
all other entries are 0
.
1 2 3 4 5 6 7 8 9 10 | # Example for a sequence of values where a tree turns "Alive" after having
# been measured "Dead"
x <- c("Alive", "Almost dead", "Dead", "Dead", "Dead", "Alive", "Dead",
"Dead", "Alive", "Dead", "Cut and Resprout", "Dead", "Alive")
detect_transitions(x, c("Dead", "Alive"))
# Extract starting points of the transition
trans <- as.logical(detect_transitions(x, c("Dead", "Alive")))
which(trans)
x[trans]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.