| add_data {exams.forge} | R Documentation |
Vector Data Addition
Description
Adds data values to a given data vector x.
Usage
add_data(x, box, n = c(0, 1), range = c(0, 1))
Arguments
x |
numeric: data vector |
box |
character or numeric: a basic box is used |
n |
numeric: number of data values on the left, the right, or both sides of |
range |
numeric: determines the range where the additional data values will be drawn from (default: |
Details
Based on the data x, or the range(box), a box is computed.
The length of the box gives the multiplier for the range.
Then a left and right interval, from which the additional values are drawn uniformly, is computed:
[left box value-range[2]*box length; left box value-range[1]*box length] (left interval) and
[right box value+range[1]*box length; right box value+range[2]*box length] (right interval).
For box, "boxplot" can be also used and quantile(x, c(0.25, 0.75), na.rm=TRUE) can be used instead of
range(x, na.rm=TRUE).
n can be a single number which will add n data values at the right side of x.
If n is a vector of length two, then n[1] data values will be added at the left side of x and
n[2] data values will be added at the right side of x.
Value
a data vector with new values
Examples
x <- rnorm(8)
# add one value to the right
add_data(x, "box", range=1.5)
add_data(x, "range", range=0.1)
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)