PreviousDate: Find Previous Test Date for Subject

PreviousDateR Documentation

Find Previous Test Date for Subject

Description

get_prev_date() identifies the previous test date for individual subjects and timepoints in a longitudinal study.

add_prev_date() interpolates these previous test dates into a data frame for further analysis.

Usage

add_prev_date(
  object,
  subject = "subject",
  timepoint = "timepoint",
  result = "result",
  prev_date = "prev_date"
)

get_prev_date(
  object,
  subject = "subject",
  timepoint = "timepoint",
  result = "result"
)

Arguments

object

a data.frame (or object coercible by as.data.frame() to a data frame) containing the data to be analysed.

subject

character, name of the column (of type integer or factor) identifying individual study subjects; default "subject".

timepoint

character, name of the column recording time points (as Dates) of testing of subjects; default "timepoint".

result

character, name of the column (of type ordered factor, or binary, see Details) recording test results; default "result".

prev_date

character, name to be used for a new column to record previous test dates; default "prev_date".

Details

See Transitions details.

Value

add_prev_date()

A data.frame based on object, with an added column named as specified by argument prev_date of class Date containing the values of the previous test dates.

get_prev_date()

A vector of class Date, length nrow(object), containing the values of the previous test dates ordered in the exact sequence of the subject and timepoint in object.

See Also

data.frame, Dates, ordered factor.

Other transitions: PreviousResult, Transitions, uniques()

Examples




 ## Continuing example from `add_transitions()`
  # subject, timepoint and result arguments all defaults and required types
Blackmore |> str()

  # Integer vector of the previous test dates
get_prev_date(Blackmore)

  # Add column of  previous test dates to data frame
add_prev_date(Blackmore) |> head(32)

rm(Blackmore)


Transition documentation built on Feb. 11, 2026, 5:07 p.m.