Learn R Programming

splinetrials (version 0.1.1)

make_visit_labels: Make Visit Labels Based on a Numeric Vector

Description

Create a character vector of values to be used as labels for a factor.

Usage

make_visit_labels(t, visit = "VIS", baseline = "BASELINE", pad = "0")

Value

A character vector of length length(t).

Arguments

t

A non-empty numeric vector of unique, finite elements in ascending order.

visit

A single character string specifying the prefix to add to t.

baseline

A single character string to use for the first timepoint's label. Alternatively, set to NULL so that all timepoints will have the prefix specified by visit.

pad

The character to use to pad between visit and t so that the places of t are aligned. Alternatively, set to NULL so that t is automatically converted to character without special formatting. This can result in numbers in labels not being aligned or not being in "alphabetical" order.

Details

Places visit as a prefix before the values of t. If pad is not NULL, the values of t are first formatted so that their places are aligned, and they are left-padded with zeros.

If baseline is not NULL it is used as the first label regardless of the value of t[1].

Uses make.unique(sep = "_") in case any elements are identical after formatting.

Examples

Run this code
make_visit_labels(c(0, 5, 13, 101))

make_visit_labels(c(0, 5.23453, 13, 101.4))

make_visit_labels(c(0, 5.23453, 13, 101.4), baseline = NULL, pad = " ")

make_visit_labels(c(0, 5.23453, 13, 101.4), visit = "Week", pad = NULL)

Run the code above in your browser using DataLab