Skip to contents

Names the direction of a change from a previous count to a current count as "up", "down" or "flat". The rules are applied in this order:

  1. both counts zero is "flat";

  2. a previous count of zero with a current count above zero is "up", so any detection where there was none is a rise;

  3. a change of threshold percent or less of the previous count, either way, is "flat";

  4. otherwise the change is "up" when the current count is the larger and "down" when it is not.

A missing count in either position gives NA. The comparison with the threshold allows a tolerance of 1e-9, so a change of exactly threshold percent is flat despite rounding.

Usage

detection_direction(current, previous, threshold = 15)

Arguments

current, previous

Numeric vectors of counts, of the same length or of length one.

threshold

Size of change, in percent, at or below which a move is called flat. Default 15.

Value

A character vector of "up", "down" and "flat".

Examples

detection_direction(c(0, 1, 23, 24, 2), c(0, 0, 20, 20, 4))
#> [1] "flat" "up"   "flat" "up"   "down"