Learn R Programming

guideR (version 0.4.0)

periods_to_long: Transform a data frame from period format to long format

Description

Transform a data frame from period format to long format

Usage

periods_to_long(
  data,
  start,
  stop,
  time_step = 1,
  time_name = "time",
  keep = FALSE
)

Value

A tibble.

Arguments

data

A data frame, or a data frame extension (e.g. a tibble).

start

<tidy-select> Time variable indicating the beginning of each row

stop

<tidy-select> Optional 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.

time_step

(numeric) Desired value for the time variable.

time_name

(character) Name of the time variable.

keep

(logical) Should start and stop variable be kept in the results?

See Also

long_to_periods()

Examples

Run this code
d <- dplyr::tibble(
  patient = c(1, 2, 3, 3),
  begin = c(0, 2, 0, 3),
  end = c(6, 4, 2, 8),
  covar = c("no", "yes", "no", "yes")
)
d

d |> periods_to_long(start = begin, stop = end)
d |> periods_to_long(start = begin, stop = end, time_step = 5)

Run the code above in your browser using DataLab