reshape.long: Reshape from Wide to Long Format

Description Usage Arguments Details Value

Description

Reshape data frames from wide to long format.

Usage

1
2
3
reshape.long <- function(data, varying.list, idvar = "id",
	ids = rownames(data), within.name = "time",
	within.levels = c("colnames","integers","letters"), drop=NULL)

Arguments

data

A data frame in wide format.

varying.list

A named list of character vectors. Each vector of this list will contain the names of the variables in data that correspond to a single variable in the long format, and the name of the vector will be the name of that new variable.

idvar

Name of the variable in data that identifies each individual, or if that variable does not exist, the name of a newly created variable that will contain that information in long format (assuming that each row of data is a different individual).

ids

Values to use for a newly created idvar variable in long format.

within.name

Character string with the name of the within-subjects factor, that will be created in long format for differentiating multiple records from the same individual.

within.levels

What will be the levels of the within-subjects factor (see Details).

drop

Variables of data that will be dropped in long format.

Details

This is a wrapper of stats::reshape with direction="long". It admits duplicated values in idvar, and the default values of ids and times are different. The argument times of reshape is defined according to the value of within.levels: "colnames" means that times will be the names of the first set of variables defined in varying.list; for "integers", they will be a sequence of integers (as the default value in reshape); for "letters" they will be an alphabetical list starting from "a" (limited to 26 levels).

Value

Reshaped data frame.


DeducerReshape documentation built on May 2, 2019, 5:20 p.m.