Learn R Programming

caroline (version 0.5.0)

groupBy: Group a datafame by a factor and perform aggreate functions.

Description

The R equvalent of a SQL 'group by' call .

Usage

groupBy(df, fact, clmns = names(df), funcs=rep('sum',length(clmns)))

Arguments

df
a data frame.
fact
the factor used to determine the grouping.
clmns
the colums to include in the output.
funcs
the functions to perform on the output (default is to sum) .

Value

  • an summary/aggregate dataframe

Examples

Run this code
e <- data.frame(a=runif(12),b=runif(12), z=rep(letters[13:18],2),w=rep(letters[20:23],3))

groupBy(df=e, fact=e$w, clmns=c('a','b'), funcs=c('sum','prod'))

Run the code above in your browser using DataLab