Learn R Programming

latrend (version 1.6.1)

which.weight: Sample an index of a vector weighted by the elements

Description

Returns a random index, weighted by the element magnitudes. This function is intended to be used as an optional strategy for trajectoryAssignments, resulting in randomly sampled cluster membership.

Usage

which.weight(x)

Value

An integer giving the index of the sampled element.

Arguments

x

A positive numeric vector.

Examples

Run this code
x = c(.01, .69, .3)
which.weight(x) #1, 2, or 3

Run the code above in your browser using DataLab