listFromLong: Convert Long Format to List Format

View source: R/listFromLong.r

listFromLongR Documentation

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
)

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'.

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.

Examples

## Not run: 
## example has been modified because package 'Synth' has been archived
## dataset 'basque' is now retrieved from archive
setwd(tempdir())
download.file("https://cran.r-project.org/src/contrib/Archive/Synth/Synth_1.1-6.tar.gz",
              destfile="Synth.tar.gz")
untar("Synth.tar.gz",files="Synth/data/basque.RData")
load("Synth/data/basque.RData")
Basque <- listFromLong(basque, unit.variable="regionno", 
                       time.variable="year", 
                       unit.names.variable="regionname")
names(Basque)
head(Basque$gdpcap)

## End(Not run)

MSCMT documentation built on Nov. 13, 2023, 5:07 p.m.