tolong_2: Long data set from wide data set

Description Usage Arguments Value Examples

Description

Creates a long data set from a wide data set identifying 'time'-varying variables by a separator

Usage

1
2
tolong_2(data, sep = "_", expand = TRUE, timevar = "time", idvar = "id",
  safe_sep = "#%@!", ...)

Arguments

data

a data frame in 'wide' form.

sep

(default: '_') the separator that identifies time-varying variables separating the 'root' containing the name of the variable in the long data set from the 'occasion' name. e.g. the separator '_' in the variable names 'y_1', 'y_2', separate the 'root', 'y', from the occasions, '1' and '2'. Default: '_'.

expand

(default TRUE) If different root names have inconsistent occasion names, should variable names be created (with NAs as values) so all root names have consistent occasion names.

timevar

(default: 'time') the variable containing the occasion names in the long file. Typically, this variable name should not exist in 'data'. If these is a conflict, an integer is appended to the name to create a new name.

idvar

(default: 'id') the variable identifying the row in the wide file from which each row in the long file is obtained. The variable should have distinct values in the wide file. If the variable does not exist in the wide file (or if it exists but does not have distinct values) a new variable is created with values equal to the row number in the wide frame.

safe_sep

is used to create unique variable name combinations when expanding time-varying variables to have consistent occasion names.

...

Other arguments are passed to list("stats::reshape").

Value

a data frame in long form in which each 'root' of a time-varying variables is a variable and the occasions are the values of the variable with name 'timevar'.

Examples

1
2
3
4
5
6
7
## Not run: 
dd <- data.frame( y.a = 1:3, y.b = 1:3, x.a= 1:3, time = 1:3,
                  x.b = 11:13, x.c = 21:23, id = c('a','a','b'))
tolong_2(dd, sep = '.')
tolong_2(dd, sep = '.', timevar = "type", idvar = 'patient')

## End(Not run)

gmonette/yscs documentation built on May 17, 2019, 7:28 a.m.