Round: Round vector to target sum

RoundR Documentation

Round vector to target sum

Description

Rounds a numeric vector constrained to sum to a target value.

Usage

Round(x, target = NULL)

Arguments

x

numeric values

target

desired sum of x after rounding

See Also

roundr; round_to

Examples

pcts <- data.frame(
  pct1 = c(33.3, 21.5, 45.51),
  pct2 = c(33.3, 33.3, 33.3)
)

## base round                                     
colSums(mapply(round, pcts))

## round to target
colSums(mapply(Round, pcts, 100))


raredd/rawr documentation built on May 9, 2024, 6:14 p.m.