forked from pharmaverse/admiral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderive_var_chg.R
35 lines (34 loc) · 955 Bytes
/
derive_var_chg.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#' Derive Change from Baseline
#'
#' Derive change from baseline (`CHG`) in a BDS dataset
#'
#' @param dataset The input dataset. Required variables are `AVAL` and
#' `BASE`.
#'
#' @details
#' Change from baseline is calculated by subtracting the baseline value
#' from the analysis value.
#'
#' @author Thomas Neitmann
#'
#' @return The input dataset with an additional column named `CHG`
#' @keywords bds derivation
#' @export
#'
#' @seealso [derive_var_pchg()]
#'
#' @examples
#' advs <- tibble::tribble(
#' ~USUBJID, ~PARAMCD, ~AVAL, ~ABLFL, ~BASE,
#' "P01", "WEIGHT", 80, "Y", 80,
#' "P01", "WEIGHT", 80.8, "", 80,
#' "P01", "WEIGHT", 81.4, "", 80,
#' "P02", "WEIGHT", 75.3, "Y", 75.3,
#' "P02", "WEIGHT", 76, "", 75.3
#' )
#' derive_var_chg(advs)
derive_var_chg <- function(dataset) {
assert_data_frame(dataset, required_vars = vars(AVAL, BASE))
dataset %>%
mutate(CHG = AVAL - BASE)
}