evenly: Create a sequence of evenly-spaced values

evenlyR Documentation

Create a sequence of evenly-spaced values

Description

For a continuous vector x, evenly and seq_min_max() create a sequence of n evenly-spaced values over the range lowerupper. By default, lower is defined as min(x) and upper as max(x), excluding NAs. For a factor x, the function returns levels(x).

Usage

evenly(x, n = 100, by = NULL, lower = NULL, upper = NULL)

seq_min_max(x, n, by = NULL, lower = NULL, upper = NULL)

Arguments

x

numeric; vector over which evenly-spaced values are returned

n

numeric; the number of evenly-spaced values to return. A default of 100 is used for convenience as that what is typically used when evaluating a smooth.

by

numeric; the increment of the sequence. If specified, argument n is ignored and the sequence returned will be from min(x) to max(x) in increments of by.

lower

numeric; the lower bound of the interval.

upper

numeric; the upper bound of the interval.

Value

A numeric vector of length n.

See Also

See base::seq() for details of the behaviour of evenly() when using by.

Examples


x <- rnorm(10)
n <- 10L

# 10 values evenly over the range of `x`
evenly(x, n = n)

# evenly spaced values, incrementing by 0.2
evenly(x, by = 0.2)

# evenly spaced values, incrementing by 0.2, starting at -2
evenly(x, by = 0.2, lower = -2)

gavinsimpson/gratia documentation built on April 24, 2024, 6:29 a.m.