Package {proratar}


Title: Proportional Allocation with Sum Consistency
Version: 0.1.0
Description: Provides robust functions for proportional allocation of numeric values. It guarantees sum consistency after rounding or integer truncation using one of two adjustment methods: the largest remainder method or max-value adjustment. Handles edge cases like NA weights and vector total values seamlessly.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.3
Suggests: testthat (≥ 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-06-11 09:28:13 UTC; HOMMA
Author: Shunsuke Homma [aut, cre]
Maintainer: Shunsuke Homma <shunsuke.homma@proton.me>
Repository: CRAN
Date/Publication: 2026-06-18 14:10:07 UTC

Proportional Allocation

Description

Proportional Allocation

Usage

prorate(total, weights, digits = NULL, adjust = c("each", "max", "none"))

Arguments

total

Scalar numeric. The total value to allocate.

weights

Numeric vector of weights. NA values are automatically treated as zero.

digits

Integer. Number of decimal places to round to. Default is NULL (no rounding).

adjust

Character or Logical. Adjustment method for total sum consistency: "each" (default) distributes the difference 1 unit by 1 unit based on remainders; "max" allocates the entire difference to the element with the largest absolute value; "none" performs no adjustment. TRUE maps to "each" and FALSE maps to "none".

Value

A numeric vector of allocated values.


Integer Proportional Allocation

Description

Integer Proportional Allocation

Usage

prorate_int(total, weights, adjust = c("each", "max", "none"))

Arguments

total

Scalar numeric or integer. The total value to allocate. Must be a whole number.

weights

Numeric vector of weights. NA values are automatically treated as zero.

adjust

Character or Logical. Adjustment method for total sum consistency: "each" (default) distributes the difference 1 unit by 1 unit based on remainders (Largest Remainder Method); "max" allocates the entire difference to the element with the largest absolute value; "none" performs no adjustment. TRUE maps to "each" and FALSE maps to "none".

Value

An integer vector of allocated values summing exactly to total.