View source: R/quest_functions.R
| ave_dfm | R Documentation | 
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.
ave_dfm(data, vrb.nm, grp.nm, fun, ...)
| data | data.frame of data. | 
| vrb.nm | character vector of colnames in  | 
| grp.nm | character vector of colnames in  | 
| 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  | 
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
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.