Learn R Programming

ribiosUtils (version 1.7.7)

isTopOrIncAndNotExcl: Logical vector of being top or included and not excluded

Description

Logical vector of being top or included and not excluded

Usage

isTopOrIncAndNotExcl(x, top = 1, incFunc, excFunc, decreasing = TRUE)

Value

A logical vector of the same length as the input x, indicating whether each element is being either top or included, and not excluded. The function can be used to keep top elements of a vector while considering both inclusion and exclusion criteria.

Arguments

x

An atomic vector that can be sorted by sort, for instance integers and character strings.

top

Integer, number of top elements that we want to consider.

incFunc

Function, applied to x to return a logical vector of the same length, indicating whether the values should be included even if it does not belong to the top elements.

excFunc

Function, applied to x to return a logical vector of the same length, indicating whether the values should be excluded even if it does belong to the top elements.

decreasing

Logical, passed to sort. The default value is set to TRUE, which means that the highest values are considered the top elements. If set to FALSE, the lowest values are considered the top elements.

Examples

Run this code
myVal <- c(2, 4, 8, 7, 1)
isTopOrIncAndNotExcl(myVal, top=1)
isTopOrIncAndNotExcl(myVal, top=3)
isTopOrIncAndNotExcl(myVal, top=3, incFunc=function(x) x>=2)
isTopOrIncAndNotExcl(myVal, top=3, excFunc=function(x) x%%2==1)
isTopOrIncAndNotExcl(myVal, top=3, incFunc=function(x) x>=2, excFunc=function(x) x%%2==1)
myVal2 <- c("a", "A", "a", "A", "A")
isTopOrIncAndNotExcl(myVal2, 2)
isTopOrIncAndNotExcl(myVal2, 2, incFunc=function(x) x=="A")
isTopOrIncAndNotExcl(myVal2, 4)
isTopOrIncAndNotExcl(myVal2, 4, excFunc=function(x) x=="a")
# \donttest{
## the function returns all TRUEs if top is larger than the length of the vector
isTopOrIncAndNotExcl(myVal, top=9)
# }

Run the code above in your browser using DataLab