Learn R Programming

doBy (version 4.5-6)

createFunBy: A template function for creating groupwise functions

Description

A template function for creating groupwise functions

Usage

createFunBy(formula, data, FUN, class = NULL, ...)

Arguments

formula
A formula containing a vertical bar (which is used for defining groups)
data
A data frame
FUN
The function to be applied
class
The class to give the result of the returned value of the created function.
...
Further arguments passed on to FUN

Value

  • A function

See Also

parseGroupFormula

Examples

Run this code
## Example: Create a function for creating groupwise t-tests

mydata <- data.frame(y=rnorm(32), x=rnorm(32),
g1=factor(rep(c(1,2),each=16)), g2=factor(rep(c(1,2), each=8)),
g3=factor(rep(c(1,2),each=4))) 


t.testBy <- function(formula, data, ...){
  createFunBy(formula, data, FUN=t.test, class="t.testBy", ...)
}

t.testBy(y~g1|g2+g3, data=mydata)

Run the code above in your browser using DataLab