Description Usage Arguments Details Value Author(s) Examples

Apply a function to row subsets of a data frame.

1 2 |

`x` |
a data frame |

`by` |
names of columns in |

`on` |
names of columns in |

`fun` |
a function that can operate on data frames that are row
subsets of |

`subset` |
logical vector (can be specified in terms of variables
in data). This row subset of |

`simplify` |
logical. If TRUE (the default), return value will
be a data frame including the |

`byvar.sep` |
character. This can be any character string not
found anywhere in the values of the |

`...` |
additional arguments to |

This function accomplishes something similar to
`by`

. The main difference is that `frameApply`

is
designed to return data frames and lists instead of objects of class
'by'. Also, `frameApply`

works only on the unique combinations of
the `by`

that are actually present in the data, not on the entire
cartesian product of the `by`

variables. In some cases this
results in great gains in efficiency, although `frameApply`

is
hardly an efficient function.

a data frame if `simplify = TRUE`

(the default), assuming
there is sufficiently structured output from `fun`

. If
`simplify = FALSE`

and `by`

is not NULL, the return value will be a list with two
elements. The first element, named "by", will be a data frame with the
unique rows of `x[by]`

, and the second element, named "result"
will be a list where the ith
component gives the result for the ith row of the "by" element.

Jim Rogers james.a.rogers@pfizer.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ```
data(ELISA, package="gtools")
# Default is slightly unintuitive, but commonly useful:
frameApply(ELISA, by = c("PlateDay", "Read"))
# Wouldn't actually recommend this model! Just a demo:
frameApply(ELISA, on = c("Signal", "Concentration"), by = c("PlateDay", "Read"),
fun = function(dat) coef(lm(Signal ~ Concentration, data =
dat)))
frameApply(ELISA, on = "Signal", by = "Concentration",
fun = function(dat, ...) {
x <- dat[[1]]
out <- c(Mean = mean(x, ...),
SD = sd(x, ...),
N = sum(!is.na(x)))
},
na.rm = TRUE,
subset = !is.na(Concentration))
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.