hash.mat {bigmemory}R Documentation

Create a hash into a “big.matrix”

Description

Create a hash into a big.matrix based on the values of the specified column.

Usage

hash.mat(x, col)

Arguments

x a big.matrix, assumed to be sorted by column col.
col an integer or name of the target column; x must be sorted on this column.

Details

When a column of a big.matrix contains many duplicated values, it can be useful to access subsets of the matrix using a hash table. To do this, the matrix must first be sorted on the entries in the desired column, and the code is designed for integer (or char or short) big.matrix matrices. Ideally, the values in the specified column should range from 1 to some maximum value that is considerably less than nrow(x).

Value

a two-column matrix, where the values in row i provide the range of indices of x containing the value i in the specified column, col.

Author(s)

John W. Emerson and Michael J. Kane

See Also

big.matrix

Examples

x <- as.big.matrix(matrix(sample(1:10, 200, replace=TRUE), 50, 4))
theorder <- order(x[,1])
for (i in 1:ncol(x)) x[,i] <- x[theorder,i]
thehash <- hash.mat(x, 1)
x[,]
thehash

# The following will produce all rows with entries 5 or 9 in the first column:
x[c(thehash[5,1]:thehash[5,2], thehash[9,1]:thehash[9,2]),]

[Package bigmemory version 3.10 Index]