View source: R/aggregatecases.R
wcAggregateCases | R Documentation |
Function to aggregate identical cases.
wcAggregateCases(x, weights = NULL, ...)
## S3 method for class 'data.frame'
wcAggregateCases(x, weights=NULL, ...)
## S3 method for class 'matrix'
wcAggregateCases(x, weights=NULL, ...)
## S3 method for class 'stslist'
wcAggregateCases(x, weights=NULL, weighted=TRUE, ...)
## S3 method for class 'wcAggregateCases'
print(x, ...)
x |
The object to aggregate. |
weights |
Numeric. An optional case weights vector. |
weighted |
Logical. If |
... |
Optional additionnal arguments. |
A wcAggregateCases
object with the following components:
Index of the unique cases in the original object data.
Aggregated case weights
Index of the original object data in the unique cases.
Original weights used.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.