Skip to contents

Coerces a vector to the strict 0/1 event coding required by survival::survfit(). Dates (and POSIXct) map to 1 when present and 0 when missing, useful for free-text recurrence-date columns. Strings are parsed against an explicit, anchored token list — no prefix matching.

Usage

.as_event01(x, mode = c("auto", "date_event", "death_event"))

Arguments

x

A vector — logical, numeric, character, Date or POSIXct.

mode

"auto" (default) treats only explicit tokens as events. "date_event" additionally treats any non-empty, non-missing value as an event (used for date-style columns such as recurrence date, where presence of a date is the event).

Value

Numeric vector of 0/1/NA, the same length as x.

Details

This function deliberately differs from the legacy v5 implementation in one place: "10 months" now returns NA, not 1. The original used grepl("^1", x), which incorrectly classified any string starting with 1 as an event.