Learn R Programming

RcmdrPlugin.survival (version 1.3-2)

unfold: Convert a Survival Data Set from "Wide" to "Long" Format

Description

Converts a survival-analysis data frame from "wide" format, in which time-varying covariates are separate variables, one per occasion, to "long" or counting-process format in which each occasion is a separate row in the data frame.

Usage

unfold(data, ...)

# S3 method for data.frame unfold(data, time, event, cov, cov.names = paste("covariate", ".", 1:ncovs, sep = ""), suffix = ".time", cov.times = 0:ncov, common.times = TRUE, lag = 0, show.progress=TRUE, ...)

Value

A data frame containing the "long" version of the data set.

Arguments

data

a data frame to be "unfolded" from wide to long.

time

the column number or quoted name of the event/censoring-time variable in data.

event

the column number or quoted name of the event/censoring-indicator variable in data.

cov

a vector giving the column numbers of the time-dependent covariate in data, or a list of vectors if there is more than one time-varying covariate.

cov.names

a character string or character vector giving the name or names to be assigned to the time-dependent covariate(s) in the output data set.

suffix

the suffix to be attached to the name of the time-to-event variable in the output data set; defaults to '.time'.

cov.times

the observation times for the covariate values, including the start time. This argument can take several forms: (1) The default is integers from 0 to the number of covariate values (i.e., one more than the length of each vector in cov). (2) An arbitrary numerical vector with one more entry than the length of each vector in cov. (3) The columns in the input data set that give the observations times for each individual. There should be one more column than the length of each vector in cov.

common.times

a logical value indicating whether the times of observation are the same for all individuals; defaults to TRUE.

lag

number of observation periods to lag each value of the time-varying covariate(s); defaults to 0.

show.progress

if TRUE, the default, show a progress bar as the observations are processed.

...

arguments to be passed down.

Author

John Fox <jfox@mcmaster.ca>

References

John Fox, Marilia Sa Carvalho (2012). The RcmdrPlugin.survival Package: Extending the R Commander Interface to Survival Analysis. Journal of Statistical Software, 49(7), 1-32. tools:::Rd_expr_doi("10.18637/jss.v049.i07").

Examples

Run this code
if (interactive()){
	head(Rossi, 2)
	Rossi.long <- unfold(Rossi, time="week", event="arrest", cov=11:62, 
	  cov.names="emp")
	head(Rossi.long, 50)
}

Run the code above in your browser using DataLab