createFunBy {doBy}R Documentation

A template function for creating groupwise functions

Description

A template function for creating groupwise functions

Usage


formulaFunBy(formula, group, data, FUN, class = NULL, ...)
xyFunBy(xy, group, data, FUN, class = NULL, ...)

Arguments

formula

A formula of the form y ~ x (which must be variable names in data).

xy

A character vector with one or two elements (which must be variable names in data).

group

A right hand sided formula or a character vector defining the grouping of data

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

Note

This function is a recent addition and has not been thoroughly tested. Please report bugs.

Author(s)

Søren Højsgaard, sorenh@math.aau.dk

See Also

parseGroupFormula

Examples


## 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.testBy1 <- function(formula, group, data, ...){
  formulaFunBy(formula, group, data, FUN=t.test, class="t.testBy1", ...)
}

t.testBy2 <- function(formula, group, data, ...){
  xyFunBy(formula, group, data, FUN=t.test, class="t.testBy1", ...)
}


t.testBy1(y~g1, ~g2+g3, data=mydata)
t.testBy2(y~x, ~g2+g3, data=mydata)


[Package doBy version 4.5-13 Index]