Learn R Programming

gmatrix (version 0.3)

rsample: Sample and integer for each row of a gmatrix object.

Description

Sample an integer with the unormalized (log) probabilities specified for each row.

Usage

rsample(P, log=TRUE)

Arguments

P
A matrix conaining unormalizes (log) probabilities in each row.
log
Specifies if the input is on a log scale.

Value

Returns a gvector with an integer value for each row.

Details

Conceptually, each row is first normalized to sum to one, and then an integer is sampled for each row under the specified probablility.

See Also

gRowLogSums