Integer vector range, coercion, sorting, duplicates removal, and type check
DESCRIPTION:
This function can be used to validate the input as an integer vector,
check the range of the input, check for duplicate values, and sort the
input. An optional coercion argument will coerce the data to the
values specified without returning a warning.
USAGE:
wavIntVec(x, min.data = NULL, max.data = NULL, duplicates = T,
sort.data = F, coerce.data = F)
REQUIRED ARGUMENTS:
- x
-
an object of any class but preferably an integer vector.
OPTIONAL ARGUMENTS:
- min.data
-
a
numeric
representing the minimum value allowed for the input data. If coerce is
TRUE
, the input is stripped of values that are less than this
argument.
- max.data
-
a numeric representing the maximum value allowed for the input data. If coerce is
TRUE
, the input is stripped of values that are greater than this
argument.
- duplicates
-
a
logical
flag. If
FALSE
, all duplicate values in the input
are removed.
- sort.data
-
a
logical
flag. If
TRUE
, the input data is sorted from low
to high.
- coerce.data
-
a
logical
flag. If
TRUE
, the data is converted to an integer
vector and the data falling outside of the range specified by the
min.data and max.data arguments will be removed. If
FALSE
, a stop error message will be
returned if any of the conditions are not met.
VALUE:
an integer vector if coerce is
TRUE
or all conditions are met, or a stop
error message describing the condition which was not met.
EXAMPLES:
## create a non-integer numeric vector
x <- c(5.3, 4.2, 3.5, 2, 1.1, 2)
## the following returns an error because x
## is not an integer vector and coerce is FALSE
wavIntVec(x, coerce = F)
## with coercion on, no error is returned
## and the data is rounded to the nearest integer.
## returns: 5 4 3 2 1 2
wavIntVec(x, coerce = T)
## do the same thing, only get rid of the
## duplicate value
## returns: 5 4 3 2 1
wavIntVec(x, coerce = T, dup = F )
## now specify a minimum and maximum value
## returns: 4 3 2
wavIntVec(x, coerce = T, dup = F, min = 2, max = 4 )
## finally, sort the data as well
## returns: 2 3 4
wavIntVec(x, coerce = T, dup = F, min = 2, max = 4, sort = T )