long: Create a longitudinal file from a wide file

Usage Arguments Examples

Usage

1
2
3
long(data, varying = NULL, sep.varying = "\.", v.names = names(Varying), timevar = "time", idvar = "id", ids = 1:NROW(data), times = seq(length = length(Varying[[1]])), drop = NULL, new.row.names = NULL, split = list(regexp = "\.", include = FALSE), debug = FALSE)

long(data, sep = "_",...)

Arguments

data
sep

(default "_" in 'tolong") the separator between the long variable name and the time

expand

(default FALSE in 'tolong') if TRUE and if there are missing combinations of long variable names and times, the missing combinations are created with NAs

varying
sep.varying
v.names
timevar
idvar
ids
times
drop
new.row.names
split
debug

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## Not run: 
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (data, varying = NULL, sep.varying = "\.", v.names = names(Varying),
    timevar = "time", idvar = "id", ids = 1:NROW(data), times = seq(length = length(Varying[[1]])),
    drop = NULL, new.row.names = NULL, split = list(regexp = "\.",
        include = FALSE), debug = FALSE)
{
    help <- "\n    Example:   long(dwl, varying = c('wmrss', 'lm1tot','lm2tot'), sep='')\n    "
    nn <- names(data)
    if (debug)
        disp(nn)
    Varying <- list()
    for (ii in 1:length(varying)) {
        if (length(prefix <- varying[[ii]]) == 1) {
            ns <- grep(paste("^", prefix, sep.varying, sep = ""),
                nn, value = T)
            if (debug)
                disp(ns)
            Varying[[ii]] <- ns
            names(Varying)[ii] <- prefix
        }
        else {
            Varying[[ii]] <- varying[[ii]]
            names(Varying)[ii] <- names(varying)[ii]
        }
    }
    if (debug)
        disp(Varying)
    if (debug)
        disp(times)
    ret <- stats::reshape(data, Varying, v.names, timevar, idvar,
        ids, times, drop, direction = "long", new.row.names,
        split)
    ret[order(ret[[idvar]], ret[[timevar]]), ]
  }



tolong <- function(data, sep = "_",...){
  reshape(data, direction = 'long', sep = sep, varying = grep(sep, names(data)),...)
}

## End(Not run)

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