add_data | R Documentation |
Generates and appends additional random values to the left and/or right ends of a numeric vector x
.
The range from which these values are drawn is determined by a specified "box" and a scaling factor.
add_data(x, box, n = c(0, 1), range = c(0, 1))
x |
|
box |
|
n |
|
range |
|
The "box" defines the central range of the data and can be:
"boxplot"
— uses the 25th and 75th percentiles (quantile(x, c(0.25, 0.75), na.rm = TRUE)
).
"range"
— uses the full range of the data (range(x, na.rm = TRUE)
).
A numeric vector of length two — used directly as the box boundaries.
The box length is the distance between the lower and upper box boundaries.
The range
parameter specifies how far left or right new values can be drawn,
as a multiple of the box length.
For the left side, values are drawn uniformly from:
[ \text{box[1]} - \text{range[2]} \times \text{box length},\; \text{box[1]} - \text{range[1]} \times \text{box length} ]
For the right side, values are drawn uniformly from:
[ \text{box[2]} + \text{range[1]} \times \text{box length},\; \text{box[2]} + \text{range[2]} \times \text{box length} ]
The n
parameter controls how many values are added:
Single number — adds that many values to the right side only.
Length-two vector — n[1]
values to the left, n[2]
values to the right.
A numeric vector containing the original values from x
plus the newly generated values.
x <- rnorm(8)
# Add one value to the right
add_data(x, "box", range = 1.5)
# Add one value to the right using data range
add_data(x, "range", range = 0.1)
# Add one value to the right, larger possible range
add_data(x, "box", range = c(1.5, 3))
# Add two values to the right
add_data(x, "range", n = 2, range = 0.1)
# Add two values to the left and three to the right
add_data(x, "range", n = c(2, 3), range = 0.1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.