int_approx: int_approx

Description Usage Arguments Details Value Examples

Description

Produce an integer vector approximation of a non-increasing non-negative numeric vector such that it sums to an positive integer

Usage

1
int_approx(vec, n)

Arguments

vec

non-decreasing non-negative numeric vector

n

A positive integer to which vector should sum to. Default value is the rounded sum of the vector

Details

The numeric vector is scaled to sum to n. Then, an integer vector is assigned the integer parts of the scaled vector. The leftout part of the sum is distributed based on the magnitude of the fractional part. This kind of approximation is useful when an algorithm produces ranking scores which have to allocated with positive integer constraints.

Value

An integer vector

Examples

1
int_approx(c(3.7, 3.2, 2.4, 1.5))

talegari/sidekicks documentation built on May 30, 2019, 8:40 a.m.