Learn R Programming

tvmediation (version 1.1.0)

LongToWide: Function to transpose the data from long to wide format

Description

Transposing a dataset with repeated measurements/responses for each subject from longitudinal to wide format.

Usage

LongToWide(subject.id, time.sequence, outcome, verbose = FALSE)

Arguments

subject.id

a column of subject identifiers

time.sequence

a column of time points

outcome

a column to be transposed

verbose

TRUE or FALSE (default = FALSE) prints output to screen (OPTIONAL INPUT)

Value

mat.wide

a matrix in wide format, in which each column is the outcome for each subject and each row is the time sequence

Details

If data is not sorted by subject.id, a warning message will appear. The function will then sort the data by subject.id. It is recommended that the user sorts the data prior to using this function.

Examples

Run this code
# NOT RUN {
# CREATING A TRANSPOSED MATRIX FOR MEDIATOR `WantToSmokeLst15min`
data(smoker)
mat.wide <- LongToWide(smoker$SubjectID,
                       smoker$timeseq,
                       smoker$WantToSmokeLst15min)

# }

Run the code above in your browser using DataLab