Count how many values are <= each specified quantile; weights optional.

DESCRIPTION:

For each specified quantile, count (1) how many values are <= that quantile, or (2) sum of weights for values that are <= that quantile.

USAGE:

countLessThan(q, values, na.rm=F, weights=NULL, op = "<=") 

REQUIRED ARGUMENTS:

q
vector of numeric quantiles
values
vector of numeric values.

OPTIONAL ARGUMENTS:

na.rm
logical, if TRUE then missing values ( NA) are removed from values and weights. If FALSE, any missing values call the result to be all NAs.
weights
either NULL (signifying that raw counts are desired) or a numeric vector the same length as values.
op
one of "<=", "<", ">=", ">"; the corresponding operation is used.

VALUE:

vector of counts or sums of weights, the same length as q. This has missing values where q is missing.

DETAILS:

The function may also work for non-numeric vectors, such as character strings, where comparisons are well-defined. It should not be used for unordered factors.

SEE ALSO:

gives answer that are smaller than here by a factor of length(values) or sum(weights).

EXAMPLES:

countLessThan( 4:6, 1:10 ) 
x <- runif(100) 
countLessThan( c(-1, .2, .5, .8, 1.5), x ) 
countLessThan( c(-1, .2, .5, .8, 1.5), x , op = "<=") # same 
countLessThan( c(-1, .2, .5, .8, 1.5), x , op = ">") 
countLessThan( c(-1, .2, .5, .8, 1.5, NA), c(x, NA), na.rm=T) 
# The final answer is NA - NAs are removed from values and weights, not q