add.random.fraction.to.cols: Add random fraction for sorting

add.random.fraction.to.colsR Documentation

Add random fraction for sorting

Description

Add a random number to a specified column, "my_col", then sort rows based on my_col, with the random fraction used to break any ties. This is a helper function used in dbRake within the raking algorithm functions (allowNegsnoMargin, noNegsnoMargin, and noNegsneedMargin), when there are more than two row groups (e.g., Regions, 5-year Age Groups, Ages, more than two sexes (when Stats Can adds more than Male and Female)).

Usage

add.random.fraction.to.cols(df, my_col)

Arguments

df

a dataframe (e.g., VarRow (e.g., for "LHA"), whichever columns being raked over, "Min")

my_col

a column in df (i.e., "Min" which is the minimum value for each row). This is the column that the rows need to be sorted by. That is, the df needs to be sorted with the VarRow with the smallest minimum value to the one with the largest minimum value, in preparation for raking.

Value

original dataframe without original my_col, but with a new sort_rows column with the order needed to sort rows

See Also

The overall raking function: dbRake()

Other raking helpers: adjustSex(), allowNegsnoMargin(), calc.cols(), multiRake(), noNegsneedMargin(), noNegsnoMargin(), prep.prorate.col(), prorate.col(), prorate.row(), prorate(), read.inputs(), real.to.int(), rename.age.grps(), rounded()


bcgov/dbutils documentation built on Sept. 30, 2022, 12:04 a.m.