findBestNpvs: Quickly Find N Smallest P-values in a Long Vector

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/ramwas.r

Description

Finding top, say, 100 p-values out of millions can be slow. This function does it much faster than the usual application of order(pv)[1:N].

Usage

1
findBestNpvs(pv, n)

Arguments

pv

Vector of p-values.

n

Number of best p-values to select.

Details

The function is a faster analog of sort(order(pv)[1:N])

Value

Return a vector of positions of the smallest N p-values in pv.

Author(s)

Andrey A Shabalin [email protected]

See Also

See order.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
pv = runif(1000)^10
n = 100

# Faster version
topSites1 = findBestNpvs(pv, n)

# Slow alternative
topSites2 = sort(order(pv)[1:n])

# The results must match
stopifnot(all( topSites1 == topSites2 ))

ramwas documentation built on Nov. 29, 2019, 2 a.m.