| linear_scale | R Documentation |
linear_scale() linearly transforms its input
vector x so that its minimum value is min
and its maximum value is max. This is for use as a
scaling function in sonscaling. It is
unlikely to be directly called by the user.
linear_scale(x, limits = NULL, soundlimits, by = NULL)
x |
A numeric vector or matrix |
limits |
The limits of the data to train, a numeric
vector of length 2. All data values outside these limits
are returned as |
soundlimits |
The limits of the sound parameter. |
by |
The unit to round the sound parameter to. See examples. |
This simple function does the important work of actually
rescaling the given data of a sonify object into
the range of the given sonic parameter, which is why it's
included in playitbyr. But it can be used on any
vector or matrix.
A numeric vector or matrix of the same type as x,
linearly rescaled in the desired way. If x only
has one value, linear_scale simply returns the
midpoint between min and max.
If by is specified, unexpected results may happen
when soundlimits[2] != (soundlimits[1] + n * by)
for some n; in these cases the data will be
trained to the largest value of (soundlimits[1] + n
* by) less than soundlimits[2].
sonscaling
x <- 1:10
linear_scale(x, soundlimits = c(-2, -1.5))
## If max<min, it's rescaled in reverse:
linear_scale(x, soundlimits = c(10, 1))
## If 'limits' is specified, these are taken as the maximum and
## minimum of the data to be rescaled to
linear_scale(x, limits = c(-10, 10), soundlimits = c(10, 0))
## any values outside of 'limits' are therefore NA in result
linear_scale(x, limits = c(1, 2), soundlimits = c(1, 10))
## 'by' rounds values appropriately
linear_scale(x, soundlimits = c(1, 2), by = .25)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.