Expand long-format data to all subject and visit combinations
Usage
complete_visits(data, id, time, response = NULL, levels = NULL)
Value
data.frame with length(levels) rows per subject
Arguments
data
(data.frame) data in long format
id
(character) name of the subject variable
time
(character) name of the visit variable. In the returned data
this variable is a factor with levels levels.
response
(character) optional name of the response variable which is
set to NA in added rows
levels
(vector) visit levels. Defaults to the levels of the visit
variable if it is a factor, and otherwise its sorted unique values.
Details
Returns a long-format data.frame with exactly one row per subject and visit
(levels), sorted by subject (in order of first appearance) and visit.
Rows that are not present in data are added by copying all columns from
the previous existing row of the subject (last observation carried
forward), or from the next existing row if there is no previous row. The
response of added rows is set to NA.