Skip to contents

Designed for usage in tsl_aggregate(). Uses linear regression to compute and return the slope of a numeric vector. Returns 0 if the length of the input vector is 1 or the linear regression fails.

Usage

f_slope(x = NULL, ...)

Arguments

x

(required, numeric vector) input vector. Default: NULL

...

(optional, additional arguments) Ignored in this function.

Value

numeric value

Examples

# Numeric vector of any length
f_slope(x = cumsum(runif(10)))
#> [1] 0.5944915

# Numeric vector with length = 1
f_slope(x = 10)
#> [1] 0

# Numeric vector with length = 0
f_slope(x = numeric(0))
#> [1] 0