Transform data from long format to period format

long_to_periods(data, .id, .start, .stop = NULL, .by = NULL)

Arguments

data

a data.frame

.id

a character, column containing individual ids

.start

a character, column containing time variable indicating the beginning of each row

.stop

a character, column containing time variable indicating the end of each row. If not provided, it will be derived from the dataset, considering that each row ends at the beginning of the next one.

.by

a character vector, co-variables to consider (optionnal)

Examples

if (FALSE) {
load(url("https://larmarange.github.io/analyse-R/data/care_trajectories.RData"))
care_trajectories
long_to_periods(care_trajectories, .id = "id", .start = "month")
long_to_periods(care_trajectories,
  .id = "id", .start = "month",
  .by = c("sex", "age", "care_status")
)
}