Description Usage Arguments Details Value Examples
Find the middles of intervals as defined by the values of their boundaries.
Makes more sense if the values of x
are ordered, but doesn't have to.
1 |
x |
A vector of numeric values |
with_borders |
A logical value stating whether the middle values should
only be in-between the first and last values of |
Basically a wrapper around the base R diff()
function. In case
with_borders = TRUE
, the first and last values are found by
reflection, see Examples
.
A vector of numeric values of shorter (if with_borders = FALSE
)
or longer (if with_borders = TRUE
) by one element than the
inputed x
vector.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | # A simple example:
x <- 1:10
centers(x)
centers(x, TRUE)
# The effect of the option on the length of the output:
length(centers(x))
length(centers(x, TRUE))
# Works also if the input is not sorted (but makes less sense):
centers(sample(x))
# Let's consider another example to illustrate the effect of the option:
x <- c(1, 2, 4, 7, 11, 16, 22)
# where
diff(x)
# Now:
centers(x)
# These values are easy to understand. Let's now see:
centers(x, TRUE)
# Here is how the first (0.5) and last (25) values are computed. The first
# one is computed so that the first value of x (1) is in the middle of the
# interval defined by the first two values of centers(x, TRUE) (0.5 and 1.5).
# Similarly, the last value (25) is computed so that the last value of x (22)
# is in the middle of the interval defined by the last two values of
# centers(x, TRUE) (19 and 25).
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.