detect_transitions: Detect value transitions

Description Usage Arguments Details Value Examples

Description

detect_transitions detects transitions between values in a vector.

Usage

1
detect_transitions(x, transition)

Arguments

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.

Details

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).

Value

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.

Examples

 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]

dschoenig/IDENTcc documentation built on May 16, 2019, 4:07 a.m.