Skip to contents

Creates a --STAT variable and, if all measurements for a visit were not done, also changes all --TESTCD values as "--ALL"

Usage

create_STAT(
  df,
  domain,
  nd_ind,
  nd_ind_cd = "Yes",
  USUBJID = "USUBJID",
  VISIT = "VISIT"
)

Arguments

df

a data frame to modify

domain

a string, the domain abbreviation in all caps

nd_ind

a string, the variable name in df that indicates if a test was not performed, usually a "Yes"/"No" or "Y"/"N" column

nd_ind_cd

a string, the code from the nd_ind column that signifies a test was not done, default is "Yes"

USUBJID

a string, the variable name in df that contains the subject identifier, default is "USUBJID"

VISIT

a string, the variable name in df that indicates a VISIT field, default is "VISIT"

Value

a modified copy of df

Examples

df <- dplyr::tibble(
  USUBJID = paste("Subject", c(rep("A", 2), rep("B", 4), rep("C", 2))),
  VISIT = paste("Visit", c(1  , 2  , 1  , 1  , 2  , 2  , 2  , 2)),
  XXTESTCD = paste("Test", c(1  , 2  , 1  , 2  , 1  , 2  , 1  , 2)),
  ND = c("N", "N", "Y", "Y", "N", "N", "Y", "Y")
)
create_STAT(df = df, domain = "XX", nd_ind = "ND", nd_ind_cd = "Y")
#> # A tibble: 6 × 5
#>   USUBJID   VISIT   XXTESTCD ND    XXSTAT  
#>   <chr>     <chr>   <chr>    <chr> <chr>   
#> 1 Subject A Visit 1 Test 1   N     NA      
#> 2 Subject A Visit 2 Test 2   N     NA      
#> 3 Subject B Visit 1 XXALL    Y     NOT DONE
#> 4 Subject B Visit 2 Test 1   N     NA      
#> 5 Subject B Visit 2 Test 2   N     NA      
#> 6 Subject C Visit 2 XXALL    Y     NOT DONE