get_extrema | R Documentation |
The function uses a sliding window of size 3 to identify extreme points via zoo::rollapply . It is designed for finding extreme points in smoothing functions, e.g., loess. In this kind of sequences it may be assumed that in most cases two consectutive entries do not have the same value. In the other rare cases a portion of -1e-12 of the difference between two points is substracted from the first point, so that for longer sequences of same values always the second one will be marked as extreme point.
get_extrema(x, format_output = c("boolean", "idxs_values"))
x |
A numeric vector to be analyzed for extreme points. |
format_output |
May be set to "boolean" or "idxs_values".
"boolean" returns boolean vectors with TRUE for local maxima and minima positions in |
A list
storing the boolean positions of extrema or the number, indices and asociated values of maxima and minima.
List style was currently chosen to allow direct use in data.table, e.g. DT[, c("minima", "maxima"):= get_extrema(column, "boolean")].
If ouptut is required as data.table
simply do as.data.table(get_extrema(...))
.
get_extrema(c(0,1,0,2,0,3), "boolean") # $minima_boolean # [1] FALSE FALSE TRUE FALSE TRUE FALSE # $maxima_boolean # [1] FALSE TRUE FALSE TRUE FALSE FALSE get_extrema(c(0,1,0,2,0,3), "idxs_values") # $minima_n # [1] 2 # $minima_idxs # $minima_idxs[[1]] # [1] 3 5 # $minima_values # $minima_values[[1]] # [1] 0 0 # $maxima_n # [1] 2 # $maxima_idxs # $maxima_idxs[[1]] # [1] 2 4 # $maxima_values #' # $maxima_values[[1]] #' # [1] 1 2 #output as data.table as.data.table(get_extrema(c(0,1,1,1,0), "idxs_values")) #<- second "1" is marked as extreme point minima_n minima_idxs minima_values maxima_n maxima_idxs maxima_values 1: 0 NA NA 1 3 1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.