The predicate is evaluated separately within each group defined by by and
must return a logical vector the same length as the group. Rows where the
predicate is FALSE are dropped and recorded in the excluded rows store.
This is the natural way to select one (or more) records per unit, e.g. the
index operation per patient.
Arguments
- criteria
A
cf_criteriaobject (orNULLto start a new one).- by
One or more column names (character vector) defining the grouping (e.g.
"participant_id"); supply more than one for composite (multi-column) grouping.- predicate
A one-sided formula evaluated within each group, or a function that receives a group's rows as a data frame and returns a logical vector.
- label
A short human-readable description of this step.
- category
An optional string grouping this step with others for display.
NULLleaves it uncategorised.- reason
An optional short description of the rows this step removes, shown in diagram exclusion boxes.
NULL(default) useslabelfor exclusion steps; for inclusion steps it should be set. See the Labels section.
See also
Other criteria builders:
cf_criteria(),
cf_criterion(),
check_criteria(),
exclude(),
group_exclude(),
group_include(),
include(),
randomise()
Examples
cf_criteria() |>
select_within(by = "participant_id",
~ consent_date == min(consent_date, na.rm = TRUE),
label = "Index operation per patient")
#> Cohort criteria pipeline (1 step)
#> 1. [>][~] (select_within) [by: participant_id] Index operation per patient
#> consent_date == min(consent_date, na.rm = TRUE)