force.range: Force Within Range

Description Usage Arguments Details Value Examples

Description

Force all elements of the input value to be within the specified range.

Usage

1

Arguments

x

A numeric vector, matrix, or data frame, possibly containing values less that min or greater than max.

min

The minimum value.

max

The maximum value.

Details

forceRange will replace all elements of x less than min with min, and all elements of x greater than max with max. If the default parameters are used, x will be returned unchanged.

Value

A matrix, vector, or data frame.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
set.seed(123)

x = rnorm(12)
y = matrix(x, ncol=4)
y
#            [,1]       [,2]       [,3]       [,4]
# [1,] -0.5604756 0.07050839  0.4609162 -0.4456620
# [2,] -0.2301775 0.12928774 -1.2650612  1.2240818
# [3,]  1.5587083 1.71506499 -0.6868529  0.3598138

forceRange(x, 0)
# [1] 0.00000000 0.00000000 1.55870831 0.07050839 0.12928774 1.71506499
# [7] 0.46091621 0.00000000 0.00000000 0.00000000 1.22408180 0.35981383

forceRange(y, -1, 1)
#            [,1]       [,2]       [,3]       [,4]
# [1,] -0.5604756 0.07050839  0.4609162 -0.4456620
# [2,] -0.2301775 0.12928774 -1.0000000  1.0000000
# [3,]  1.0000000 1.00000000 -0.6868529  0.3598138

lcmix documentation built on May 31, 2017, 5 a.m.

Search within the lcmix package
Search all R packages, documentation and source code