monotonic {brolgar} R Documentation

## Are values monotonic? Always increasing, decreasing, or unvarying?

### Description

These provides three families of functions to tell you if values are always increasing, decreasing, or unvarying, with the functions, `increasing()`, `decreasing()`, or `unvarying()`. Under the hood it uses `diff` to find differences, so if you like you can pass extra arguments to `diff`.

### Usage

```increasing(x, ...)

decreasing(x, ...)

unvarying(x, ...)

monotonic(x, ...)
```

### Arguments

 `x` numeric or integer `...` extra arguments to pass to diff

### Value

logical TRUE or FALSE

### Examples

```vec_inc <- c(1:10)
vec_dec<- c(10:1)
vec_ran <- c(sample(1:10))
vec_flat <- rep.int(1,10)

increasing(vec_inc)
increasing(vec_dec)
increasing(vec_ran)
increasing(vec_flat)

decreasing(vec_inc)
decreasing(vec_dec)
decreasing(vec_ran)
decreasing(vec_flat)

unvarying(vec_inc)
unvarying(vec_dec)
unvarying(vec_ran)
unvarying(vec_flat)

library(ggplot2)
library(gghighlight)
library(dplyr)

heights_mono <- heights %>%
features(height_cm, feat_monotonic) %>%
left_join(heights, by = "country")

ggplot(heights_mono,
aes(x = year,
y = height_cm,
group = country)) +
geom_line() +
gghighlight(increase)

ggplot(heights_mono,
aes(x = year,
y = height_cm,
group = country)) +
geom_line() +
gghighlight(decrease)

heights_mono %>%
filter(monotonic) %>%
ggplot(aes(x = year,
y = height_cm,
group = country)) +
geom_line()

heights_mono %>%
filter(increase) %>%
ggplot(aes(x = year,
y = height_cm,
group = country)) +
geom_line()

```

[Package brolgar version 0.1.1 Index]