tolong_2 | R Documentation |
Creates a long data set from a wide data set identifying 'time'-varying variables by a separator
tolong_2(
data,
sep = "_",
expand = TRUE,
timevar = "time",
idvar = "id",
safe_sep = "#%@!",
...
)
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 |
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'.
tolong
and towide
for many examples using both 'towide' and 'tolong'.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.