These function constructors create functions suitable for use in relational-join recipes that expand or contract the row-dimension of the incoming data.

rep_per_key(keyvar, tblnm, count, prop_present = 1)

rand_per_key(keyvar, tblnm, mincount = 1, maxcount = 20, prop_present = 0.5)

Arguments

keyvar

character(1). The name of the column to treat as a foreign key.

tblnm

character(1). The name of the table in the database in which to find the keyvar

count

numeric(1). The number of times each foreign-key value should appear in the scaffold data.

prop_present

numeric(1). Proportion of the key values in the foreign table to include rows for in the dimension-scaffold. Defaults to 1 (all values present).

mincount

numeric(1). Minimum replications for a present key

maxcount

numeric(1). Maximum replications for a pressent key

Details

rep_per_key creates functions which generate dimension-scaffolds that contain a constant number of rows per key value (ie row of the incoming data), e.g., the the map from ADSL requires 3 rows per patient (foreign key) to synthesize the long-form PARAMCD-based ADTTE data.

rand_per_key creates functions which generate dimension-scaffolds which contain a uniformly distributed random number of rows per key value. An example of this would be that for adverse events, a patient can have anywehre from 0 to 20 adverse events, each of which is a separate row in the new dimensions.

Examples

foreign_tbl <- data.frame(id = 1:5) perkey_fun <- rep_per_key("id", tblnm = "foreign_tbl", 2, .6) perkey_fun(.db = list(foreign_tbl = foreign_tbl))
#> id #> 1 1 #> 2 1 #> 3 2 #> 4 2 #> 5 3 #> 6 3 #> 7 4 #> 8 4
randrep_fun <- rand_per_key("id", tblnm = "foreign_tbl", mincount = 1, maxcount = 5) randrep_fun(.db = list(foreign_tbl = foreign_tbl))
#> id #> 1 3 #> 2 3 #> 3 3 #> 4 3 #> 5 3 #> 6 4 #> 7 4 #> 8 5 #> 9 5 #> 10 5