Skip to contents

A fact_schema object is created, the essential data is a name and a set of measures that can be empty (does not have explicit measures). It is part of a star_schema object, defines the facts of the star schema.

Usage

fact_schema(
  name = NULL,
  measures = NULL,
  agg_functions = NULL,
  nrow_agg = NULL
)

Arguments

name

A string, name of the fact.

measures

A vector of measure names.

agg_functions

A vector of aggregation function names, each one for its corresponding measure. If none is indicated, the default is SUM. Additionally they can be MAX or MIN.

nrow_agg

A string, name of a new measure that represents the COUNT of rows aggregated for each resulting row.

Value

A fact_schema object.

Details

Associated with each measure there is an aggregation function that can be SUM, MAX or MIN. AVG is not considered among the possible aggregation functions: The reason is that calculating AVG by considering subsets of data does not necessarily yield the AVG of the total data.

An additional measure corresponding to the COUNT of aggregated rows is added which, together with SUM, allows us to obtain the AVG if needed.

See also

star_database

Other star schema definition functions: define_dimension(), define_facts(), dimension_schema(), star_schema()

Examples


f <- fact_schema(
  name = "mrs_cause",
  measures = c(
    "Pneumonia and Influenza Deaths",
    "Other Deaths"
  )
)

f <- fact_schema(
  name = "mrs_cause",
  measures = c(
    "Pneumonia and Influenza Deaths",
    "Other Deaths"
  ),
  agg_functions = c(
    "MAX",
    "SUM"
  ),
  nrow_agg = "Nrow"
)