Skip to contents

Assigns the "[DOMAIN]SEQ" number by sorting the data set by the specified variables and then grouping by "USUBJID".

Usage

assign_SEQ(tbl, key_vars, seq_prefix, USUBJID = "USUBJID")

Arguments

tbl

a data frame, the SDTM table

key_vars

a character vector of the key variables to sort by

seq_prefix

a string, the prefix for SEQ as per the spec (usually the two letter domain abbreviation)

USUBJID

a string, the column for the subject ID, USUBJID, default is "USUBJID"

Value

a sorted copy of the tbl data frame with the new SEQ column

Examples

df <- data.frame(
  USUBJID = paste("Subject", c(rep(1, 3), rep(2, 3))),
  XXTESTCD = paste("T", rep(c(2, 3, 1), 2))
)
assign_SEQ(df, key_vars = c("USUBJID", "XXTESTCD"), seq_prefix = "XX")
#> # A tibble: 6 × 3
#>   USUBJID   XXTESTCD XXSEQ
#>   <chr>     <chr>    <int>
#> 1 Subject 1 T 1          1
#> 2 Subject 1 T 2          2
#> 3 Subject 1 T 3          3
#> 4 Subject 2 T 1          1
#> 5 Subject 2 T 2          2
#> 6 Subject 2 T 3          3