Learn R Programming

aCRM (version 0.1.1)

Aggregate: Aggregate numeric and categorical variables by an ID

Description

The Aggregate function (not to be confounded with aggregate) prepares a data frame for merging by computing the sum, mean and variance of all continuous (integer and numeric) variables by a given ID variable. It also creates dummies for all categorical variables (character and factor) and subsequently computes the sum by a given ID variable. This functions aims at maximal information extraction with a minimal amount of code.

Usage

Aggregate(x, by)

Arguments

x
A data frame without the ID. Categorical variables have to be of type character or factor and continuous variables have to be of type integer or numeric.
by
A vector containing ID''s.

Value

A data frame with the aforementioned variables aggregated by the given ID variables.

References

Van den Poel, D., Ballings, M., Volkov, A., D''haen, J., Van Herwegen, M., Predictive Analytics for analytical Customer Relationship Management using SAS, Oracle and R, Springer, Forthcoming.

See Also

Other functions in this package: imputeMissings, Aggregate, cocktailEnsemble, predict.cocktailEnsemble

Examples

Run this code
#Create some data
data <- data.frame(V1=as.factor(c('yes','no','no','yes','yes','yes','yes')),
                    V2=as.character(c(1,2,3,4,4,4,4)),V3=c(1:7),V4=as.numeric(c(7:1)))
ID=as.character(c(1,1,1,1,2,2,2))
#Demonstrate function
Aggregate(x=data,by=ID)

Run the code above in your browser using DataLab