Learn R Programming

MSCMT (version 1.4.0)

listFromLong: Convert Long Format to List Format

Description

listFromLong converts long to list format.

Usage

listFromLong(
  foo,
  unit.variable,
  time.variable,
  unit.names.variable = NULL,
  exclude.columns = NULL
)

Value

A list of matrices with rows corresponding to the times and columns corresponding to the unit (or unit names, respectively) for all columns of foo which are neither excluded nor have a special role as time, unit, or unit names variable.

Arguments

foo

A data.frame containing the data in "long" format.

unit.variable

Either a numeric scalar with the column number (in foo) containing the units or a character scalar with the corresponding column name in foo.

time.variable

Either a numeric scalar with the column number (in foo) containing the times or a character scalar with the corresponding column name in foo.

unit.names.variable

Optional. If not NULL, either a numeric scalar with the column number (in foo) containing the unit names or a character scalar with the corresponding column name in foo. Must match with the units defined by unit.variable (if not NULL).

exclude.columns

Optional (defaults to NULL). Numeric vector with column numbers of foo to be excluded from the conversion.

Details

listFromLong is a convenience function to convert long format (in a data.frame, as used by package 'Synth') to list format, where data is stored as a list of matrices.

Most parameter names are named after their equivalents in the dataprep function of package 'Synth'.

Examples

Run this code
if (require("Synth")) {
  data(basque)
  Basque <- listFromLong(basque, unit.variable="regionno", 
                         time.variable="year", 
                         unit.names.variable="regionname")
  names(Basque)
  head(Basque$gdpcap)
}

Run the code above in your browser using DataLab