Learn R Programming

SSBtools (version 0.8.0)

FormulaSums: Sums (aggregates) and/or sparse model matrix with possible cross table

Description

By default this function return sums if the formula contains a response part and a model matrix otherwise

Usage

FormulaSums(
  data,
  formula,
  makeNames = TRUE,
  crossTable = FALSE,
  total = "Total",
  printInc = FALSE,
  dropResponse = FALSE,
  makeModelMatrix = NULL,
  sep = "-",
  sepCross = ":"
)

Formula2ModelMatrix(data, formula, dropResponse = TRUE, ...)

Arguments

data

data frame

formula

A model formula

makeNames

Column/row names made when TRUE

crossTable

Cross table in output when TRUE

total

String used to name totals

printInc

Printing "..." to console when TRUE

dropResponse

When TRUE response part of formula ignored.

makeModelMatrix

Make model matrix when TRUE. NULL means automatic.

sep

String to separate when creating column names

sepCross

String to separate when creating column names involving crossing

...

Further arguments to be passed to FormulaSums

Value

A matrix of sums, a sparse model matrix or a list of three elements (model matrix, cross table and sums).

Details

The model matrix is constructed by calling fac2sparse() repeatedly. The sums are computed by calling aggregate() repeatedly. Hierarchical variables handled when constructing cross table. Column names constructed from the cross table.

Examples

Run this code
# NOT RUN {
x <- SSBtoolsData("sprt_emp_withEU")

FormulaSums(x, ths_per ~ year*geo + year*eu)
FormulaSums(x, ~ year*age*eu)
FormulaSums(x, ths_per ~ year*age*geo + year*age*eu, crossTable = TRUE, makeModelMatrix = TRUE)
FormulaSums(x, ths_per ~ year:age:geo -1)
# }

Run the code above in your browser using DataLab