Learn R Programming

SciencesPo (version 1.3.7)

compute: Aggregate a numeric variable

Description

Aggregate a numeric variable

Usage

compute(.data, formula, FUN)

Arguments

.data
The data object.
formula
The variable versus factor(s) to be computed (y~factor+factor).
FUN
The function statistic to be calculated.

encoding

UTF-8

Examples

Run this code
# data:
df=data.frame(group=sample(letters,100, TRUE),y=sample(100) )

#functions:
FUNS <- function(x) c(N=nrow(x), mean=round(mean(x),0),
sd=round(sd(x), 0), min=round(min(x),0),
max=round(max(x),0))

# Do the computation
compute(df, y~group, FUN=FUNS)

Run the code above in your browser using DataLab