reshapeLong {base} | R Documentation

## Reshape data frame to long format

### Description

(EXPERIMENTAL). Convert data frame with repeated measurements in wide format with repeated observations in multiple variables across rows to long format, 1 row per observation.

### Usage

    reshapeLong(x, jvars, ilev=row.names(x), jlev=names(x)[jvars],
                iname="reshape.i", jname="reshape.j", vname="reshape.v")

### Arguments

`x` | The data frame to convert
`jvars` | The variables to reshape by
`ilev` | Levels of 1st indexing factor
`jlev` | Levels of 2nd indexing factor
`iname` | Name of 1st indexing factor
`jname` | Name of 2nd indexing factor
`vname` | Name of variable holding the combined values of the "across" variables

### Details

This causes the values in `jvars` to be combined into a single variable, all other variables being replicated the relevant number of times. Two factors are added to the data frame indicating rows and columns of the original data format.

### Value

The reshaped data frame.

### Bugs

There ought to be a way to have multiple sets of `jvars` variables.

### Note

The same substitution tricks are used for `jvars` as for the `select` argument to `subset`. I.e. the argument is treated as an expression and variables are replaced with their number in the data frame, allowing ranges of variables to be specified.

### See Also

`reshapeWide`, `stack`

### Examples

    (dd<-as.data.frame(matrix(1:24,4)))
    reshapeLong(dd,V3:V5)