
Flag Completion Status at Event, Session, and/or Applicant Level
flag_completed.RdCreates binary completion flag columns on a web analytics dataframe,
indicating whether an applicant completed the target event
(ApplicantSharedIncomeSummary) at the event, session, and/or
applicant level.
Usage
flag_completed(df, type = c("event", "session", "applicant"))Arguments
- df
A dataframe containing web analytics data. Must include the following columns:
eventCharacter. The name of the tracked event.
pilotCharacter or factor. The pilot group identifier, used as a grouping variable for session- and applicant-level flags.
cbv_flow_idCharacter or numeric. A unique session identifier. Required when
"session"is included intype.distinct_idCharacter or numeric. A unique applicant identifier. Required when
"applicant"is included intype.
- type
Character vector specifying which completion flags to generate. One or more of:
"event"Adds
completed_event:TRUEif the row's event isApplicantSharedIncomeSummary,FALSEotherwise."session"Adds
completed_session:TRUEif any event within the samepilot+cbv_flow_idsession is a completion event."applicant"Adds
completed_applicant:TRUEif any event across all sessions for the samepilot+distinct_idapplicant is a completion event.
Defaults to
c("event", "session", "applicant")(all three).
Value
A dataframe with the same rows as df, with one or more of
the following columns appended depending on type:
completed_eventLogical. Row-level completion flag. Included only if
"event"is intype.completed_sessionLogical. Session-level completion flag. Included only if
"session"is intype.completed_applicantLogical. Applicant-level completion flag. Included only if
"applicant"is intype.
Details
The target completion event is defined internally as
"ApplicantSharedIncomeSummary". A row-level completed_event
flag is first created, then session- and applicant-level flags are derived
by applying any() within each group. any() returns TRUE
if at least one value in the group is TRUE, making the aggregation
logic explicit and self-documenting.
If "event" is not included in type, the intermediate
completed_event column is dropped from the returned dataframe.
Grouping configurations for "session" and "applicant" are
defined internally and applied functionally via purrr::reduce(),
making it straightforward to extend the function with additional grouping
levels in the future.
Examples
if (FALSE) { # \dontrun{
# Add all three flags (default)
df_flagged <- flag_completed(df)
# Add only the applicant-level flag
df_flagged <- flag_completed(df, type = "applicant")
# Add session and applicant flags, but not the raw event-level flag
df_flagged <- flag_completed(df, type = c("session", "applicant"))
} # }