towide: Wide data set from long data set

Description Usage Arguments Details Value Examples

View source: R/towide.R

Description

Creates a wide data set from a long data set identifying an 'id' variable and using a time variable whose values provide suffixes for time-varying variable names in wide form.

Usage

1
towide(data, idvar = "id", timevar = "time", sep = "_")

Arguments

data

a data frame in 'long' form.

idvar

(default: 'id') the variable identifying each group of rows that are transformed to a single row in the wide file.

timevar

(default: 'time') the variable containing the occasion names in the long file.

sep

(default: '_') the character(s) that separate the name of the a time-varying variable in the long form from the added suffix for the correponding names in wide form. Default: '_'.

...

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

Details

In contrast with reshape in stats, this function identifies variables that are invariant with respect to 'idvar' and does not expand them to wide form. Only 'time'-varying variables are expanded to wide form.

Value

a data frame in wide form in which each variable that varies within levels of 'idvar' is turned into as many variables as there are distinct values of 'timevar' using the values of 'timevar' as suffixes to name the variables in wide form.

Examples

1
2
3
4
5
6
7
8
## 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(dd, sep = '.')
dl <- tolong(dd, sep = '.', timevar = "type", idvar = 'patient')
towide(dl, idvar = 'patient', timevar = 'type')

## End(Not run)

gmonette/spida documentation built on May 17, 2019, 7:25 a.m.