Learn R Programming

WeightedCluster (version 1.8-0)

wcAggregateCases: Aggregate identical cases.

Description

Function to aggregate identical cases.

Usage

wcAggregateCases(x, weights = NULL, ...)
# S3 method for data.frame
wcAggregateCases(x, weights=NULL, ...) 
# S3 method for matrix
wcAggregateCases(x, weights=NULL, ...) 
# S3 method for stslist
wcAggregateCases(x, weights=NULL, weighted=TRUE, ...)
# S3 method for wcAggregateCases
print(x,  ...)

Value

A wcAggregateCases object with the following components:

aggIndex

Index of the unique cases in the original object data.

aggWeights

Aggregated case weights

disaggIndex

Index of the original object data in the unique cases.

disaggWeights

Original weights used.

Arguments

x

The object to aggregate.

weights

Numeric. An optional case weights vector.

weighted

Logical. If TRUE, the weights are taken from the sequence object (see seqdef).

...

Optional additionnal arguments.

Examples

Run this code
data(mvad)
## Taking only the father unemployment and 
## success at the end of compulsory schooling.
myData <- mvad[ , c("funemp", "gcse5eq")]
## Computing aggregated cases informations
ac <- wcAggregateCases(myData, weights=mvad$weight)
print(ac)
## Retrieving unique cases in the original data set
uniqueData <- myData[ac$aggIndex, ]
## Table from original data
table.orig <- xtabs(mvad$weight~funemp+gcse5eq, data=myData)

## Table from aggregated data
table.agg <- xtabs(ac$aggWeights~funemp+gcse5eq, data=uniqueData)

## Both table are equal, no information is lost 
## (only the call command is different)
all(table.orig == table.agg)

Run the code above in your browser using DataLab