View source: R/filter_joined.R
max_cond | R Documentation |
The function derives the maximum value of a vector/column on a subset of entries/observations.
max_cond(var, cond)
var |
A vector |
cond |
A condition |
Utilities for Filtering Observations:
count_vals()
,
filter_exist()
,
filter_extreme()
,
filter_joined()
,
filter_not_exist()
,
filter_relative()
,
min_cond()
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",
)
# In oncology setting, when needing to check the first time a patient had
# a Complete Response (CR) to compare to see if any Partial Response (PR)
# occurred after this add variable indicating if PR occurred after CR
group_by(data, USUBJID) %>% mutate(
first_cr_vis = min_cond(var = AVISITN, cond = AVALC == "CR"),
last_pr_vis = max_cond(var = AVISITN, cond = AVALC == "PR"),
pr_after_cr = last_pr_vis > first_cr_vis
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.