createFunBy {doBy} | R Documentation |
A template function for creating groupwise functions
formulaFunBy(formula, group, data, FUN, class = NULL, ...) xyFunBy(xy, group, data, FUN, class = NULL, ...)
formula |
A formula of the form |
xy |
A character vector with one or two elements (which must be
variable names in |
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 |
A function
This function is a recent addition and has not been thoroughly tested. Please report bugs.
Søren Højsgaard, sorenh@math.aau.dk
## 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)