Learn R Programming

SoupX (version 1.4.8)

alloc: Allocate values to "buckets" subject to weights and constraints

Description

Allocates tgt of something to length(bucketLims) different "buckets" subject to the constraint that each bucket has a maximum value of bucketLims that cannot be exceeded. By default counts are distributed equally between buckets, but weights can be provided using ws to have the redistribution prefer certain buckets over others.

Usage

alloc(tgt, bucketLims, ws = rep(1/length(bucketLims), length(bucketLims)))

Arguments

tgt

Value to distribute between buckets.

bucketLims

The maximum value that each bucket can take. Must be a vector of positive values.

ws

Weights to be used for each bucket. Default value makes all buckets equally likely.

Value

A vector of the same length as bucketLims containing values distributed into buckets.

Examples

Run this code
# NOT RUN {
set.seed(1137)
ws = abs(rnorm(10))
tops = round(runif(10)*3)
#Simple case where the bucket limits change nothing
SoupX:::alloc(1,tops,ws)
#Case where some buckets get full
SoupX:::alloc(8,tops,ws)
# }

Run the code above in your browser using DataLab