| shapevar | R Documentation |
Converts repeated-measures data from wide to long format or from long to
wide format using base R only. The active R4VN data frame is used when
data is omitted.
shapevar(
to = NULL,
long = FALSE,
wide = FALSE,
id,
vars,
time = time,
value = value,
times = NULL,
sep = "_",
data = NULL,
quiet = FALSE
)
to |
Optional target shape: |
long, wide |
Logical shortcuts. Use exactly one when |
id |
One or more subject/record identifier variables. Use a bare name or
|
vars |
Variables to reshape, usually supplied by |
time |
Name of the time/index variable. In wide-to-long conversion this is the new time variable; in long-to-wide conversion it is an existing variable. |
value |
Name of the new value variable for wide-to-long conversion. Ignored for long-to-wide conversion. |
times |
Optional values assigned to the repeated wide columns. When
omitted, |
sep |
Separator between value-variable names and time values when creating wide variable names. |
data |
Optional explicit data-frame object. When omitted, active data is reshaped and replaced directly. |
quiet |
Logical; suppress the reshape summary. |
Wide to long example:
shapevar(long = TRUE, id = id, vars = vars(bp1, bp2, bp3),
time = visit, value = bp)
Long to wide example:
shapevar(wide = TRUE, id = id, time = visit, vars = vars(bp))
For long-to-wide conversion, each id by time combination must be unique.
Variables not included in vars are preserved when they are constant within
each ID. A changing non-reshaped variable triggers an error rather than being
silently discarded.
The reshaped data frame invisibly.
wide <- data.frame(id = 1:2, sex = c("F", "M"),
bp1 = c(120, 130), bp2 = c(118, 128), bp3 = c(116, 125))
usedf(wide, quiet = TRUE)
shapevar(long = TRUE, id = id, vars = vars(bp1, bp2, bp3),
time = visit, value = bp, quiet = TRUE)
long <- usedf(quiet = TRUE)
shapevar(wide = TRUE, id = id, time = visit, vars = vars(bp), quiet = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.