# ave_dfm: Repeated Group Statistics for a Data-Frame In quest: Prepare Questionnaire Data for Analysis

## Description

`ave_dfm` evaluates a function on a set of variables `vrb.nm` separately for each group within `grp.nm`. The results are combined back together in line with the rows of `data` similar to `ave`. `ave_dfm` is different than `ave` or `agg` because it operates on a data.frame, not an atomic vector.

## Usage

 `1` ```ave_dfm(data, vrb.nm, grp.nm, fun, ...) ```

## Arguments

 `data` data.frame of data. `vrb.nm` character vector of colnames in `data` specifying the variables to use for the aggregation function `fun`. `grp.nm` character vector of colnames in `data` specifying the grouping variables. `fun` function that returns an atomic vector of length 1. Probably makes sense to ensure the function always returns the same typeof as well. `...` additional named arguments to `fun`.

## Value

atomic vector of length = `nrow(data)` providing the result of the function `fun` for the subset of data with that group value (i.e., `data[levels(interaction(data[grp.nm]))[i], vrb.nm]`) for that row.

`ave` for the same functionality with atomic vector inputs `agg_dfm` for similar functionality with data.frames, but can return the result for each group once rather than repeating the result for each group value in the data.frame
 ```1 2 3 4 5 6 7``` ```# one grouping variables ave_dfm(data = airquality, vrb.nm = c("Ozone","Solar.R"), grp.nm = "Month", fun = function(dat) cor(dat, use = "complete")[1,2]) # two grouping variables ave_dfm(data = mtcars, vrb.nm = c("mpg","cyl","disp"), grp.nm = c("vs","am"), fun = nrow) # with multiple group columns ```