count_peaks: Count the number of peaks in a series of values

View source: R/sequence_characteristics.R

count_peaksR Documentation

Count the number of peaks in a series of values

Description

Peaks are identified as patterns of increase, possibly followed by a constant stretch, which ends in a decrease.

Usage

count_peaks(x, min_change = 0)

Arguments

x

A numeric vector

min_change

A numeric value. The size of a minimal change between two consecutive values of x to count as increase/decrease.

Value

An integer value representing the number of peaks

Examples

count_peaks(c(0, 1, 0, 1, 0)) ## expect 2 peaks
count_peaks(c(0, 1, 0, 1)) ## expect 1 peak
count_peaks(c(1, 0, 1)) ## expect 0 peak
count_peaks(c(0, 1, 1, 2.5, 5.1, 4.9)) ## expect 1 peak
count_peaks(c(0, 1, 1, 2.5, 5.1, 4.9), min_change = 0.5) ## expect 0 peak
count_peaks(c(0, 1, 1, 0.8, 5.1, 4)) ## expect 2 peak
count_peaks(c(0, 1, 1, 0.8, 5.1, 4), min_change = 0.1) ## expect 2 peak
count_peaks(c(0, 1, 1, 0.8, 5.1, 4), min_change = 0.5) ## expect 1 peak


DrylandEcology/rSW2utils documentation built on Dec. 9, 2023, 10:44 p.m.