Assures that what is returned is an integer within the specified range. Real values are truncated. Non-numerics are forced to minimum without warning.
withinIntegerRange(int = 0, minimum = 0, maximum = 0, na = "min")
int | value to be forced within a range |
---|---|
minimum | minimum integer value. |
maximum | maximum integer value |
na | if "min" then non-numerics are forced to the minimum in the range If "max" then non-numerics are forced to the maximum in the range. If not either "min" or "max" it is forced to "min". |
A vector of integers forced to be within the specified range.
#> [1] 0withinIntegerRange( , 0, 10)#> [1] 0withinIntegerRange(NA, 0, 10, na = "max")#> [1] 10withinIntegerRange( , 0, 10, na = "max") # no argument is not NA#> [1] 0withinIntegerRange(LETTERS, 0, 10)#> [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0withinIntegerRange(2.6, 1, 5)#> [1] 2withinIntegerRange(2.6, 0, 2)#> [1] 2#> [1] 0 2 0#> [1] 0 2 0 0#> [1] 0 2 0 2#> [1] 0 2 0 0# }