Learn R Programming

GaussSuppression (version 0.9.6)

Ncontributors: Find the number of unique groups contributing to aggregates

Description

Assuming aggregates are calculated via a dummy matrix by z = t(x) %*% y, the the number of unique contributing groups, according to a grouping variable, are found for each aggregate. The missing group category is not counted.

Usage

Ncontributors(x, groups)

Value

Vector of numbers of unique groups

Arguments

x

A (sparse) dummy matrix

groups

Vector of group categories

Author

Øyvind Langsrud

See Also

ModelMatrix

Examples

Run this code
library(SSBtools)

z <- SSBtoolsData("sprt_emp_withEU")
z$age[z$age == "Y15-29"] <- "young"
z$age[z$age == "Y30-64"] <- "old"
z$groups <- c("A", "A", "B", "A", "B", "C")

a <- ModelMatrix(z, formula = ~age*eu + geo + year, crossTable = TRUE)

cbind(as.data.frame(a$crossTable), nGroups = Ncontributors(a$modelMatrix, z$groups))
cbind(as.data.frame(a$crossTable), nYears = Ncontributors(a$modelMatrix, z$year))
cbind(as.data.frame(a$crossTable), nUnique_ths_per = Ncontributors(a$modelMatrix, z$ths_per))

Run the code above in your browser using DataLab