findFirstFeature: Feature matrix feature locator.

Description Usage Arguments Details Value Examples

View source: R/utils.R

Description

Finds the first feature in a feature matrix that has its specified element at a given key equal to a given target. If no feature satisfies the requirement, counts how many features have, at the same key, an element strictly less than the target (its rank in the matrix).

Usage

1
findFirstFeature(sortedFeatureMatrix, key = RT_IDX, target = 0)

Arguments

sortedFeatureMatrix

The sorted feature matrix to search.

key

The column in the matrix to search in.

target

The target value to search for, as a number.

Details

This function uses binary search to find the feature, so the feature matrix must be sorted ascending in the key column. Otherwise there is no guarantee that the search will yield the correct result.

Value

The index of the first feature that has its element at the given key equal to the given target, if it exists; the feature's rank otherwise.

Examples

1
2
3
4
5
6
7
8
## Not run: 
m <- matrix(1:10, nrow = 5, ncol = 2)
m[2, 1] <- 3
m[4, 1] <- 3
rank <- findFirstFeature(m, key = 1, target = 3)
rank  # Returns 2

## End(Not run)

ychen-uoft/msFeatureCmp documentation built on Dec. 23, 2021, 7:17 p.m.