library(tibble)
library(dplyr, warn.conflicts = FALSE)
library(admiral)
data <- tribble(
~USUBJID, ~AVISITN, ~AVALC,
"1", 1, "PR",
"1", 2, "CR",
"1", 3, "NE",
"1", 4, "CR",
"1", 5, "NE",
"2", 1, "CR",
"2", 2, "PR",
"2", 3, "CR",
"3", 1, "CR",
"4", 1, "CR",
"4", 2, "NE",
"4", 3, "NE",
"4", 4, "CR",
"4", 5, "PR"
)
# add variable providing the number of NEs for each subject
group_by(data, USUBJID) %>%
mutate(nr_nes = count_vals(var = AVALC, val = "NE"))
Run the code above in your browser using DataLab