# NOT RUN {
library(magrittr)
library(wrangle)
library(dplyr)
data(events)
x <- events
# Step 0. Rename columns to remove semantic (non-syntactic) underscores.
# Step 1. De-interlace the data. Limit to a subset so that each column means only one thing.
x %<>% filter(CMT == 2) %>% select(-EVID,-CMT,-AMT)
# Step 2. Describe the groups (unique key). Order is important. (Start with most general.)
x %<>% group_by(USUBJID, TIME)
x %>% status
# Step 3. Supply metadata as values or factors. Hardcode or merge from source.
x %<>% mutate(
ID_LABEL = 'subject identifier',
C_LABEL = 'comment flag',
USUBJID_LABEL = 'universal subject identifier',
TIME_LABEL = 'time',
DV_LABEL = 'parent drug',
BLQ_LABEL = 'below limit of quantitation',
LLOQ_LABEL = 'lower limit of quantitation',
TAD_LABEL = 'time since most recent dose',
SEX_LABEL = 'sex',
WT_LABEL = 'weight',
PRED_LABEL = 'population prediction'
)
x %<>% mutate(
C_GUIDE = factor(paste(C), exclude = NULL,
levels = c('NA','C'),
labels = c('not commented','commented')),
TIME_GUIDE = 'h',
DV_GUIDE = 'ng/mL',
BLQ_GUIDE = factor(BLQ,
levels = 0:1,
labels = c('not quantifiable','quantifiable')),
LLOQ_GUIDE = 'ng/mL',
TAD_GUIDE = 'h',
SEX_GUIDE = factor(SEX,
levels = 0:1,
labels = c('female','male')),
WT_GUIDE = 'kg',
PRED_GUIDE = 'ng/mL'
)
# Step 4. Fold and unfold your data.
x %>% fold
x %>% fold %>% unfold
x %>% fold %>% unfold %>% fold
x %>% fold %>% unfold(PRED,TIME,WT)
data(eventsf)
stopifnot(identical(x %>% fold, eventsf) )
# }
Run the code above in your browser using DataLab