#' Applies given function to given groups separately
#'
#' @param data data frame
#' @param groups group vector
#' @param FUN function to apply
#' @param ... parameters fo function
#'
#' @return
#' @export
#'
#'
gapply <- function(data, groups, FUN, ...) {
if(!hasArg(data)) {
message("Find data frame.")
data <- getData()
}
if(!hasArg(groups)) {
message("Find groups vector.")
groups <- getData()
}
groups <- groups[rownames(data)]
u.groups <- unique(groups)
for(i in 1:length(u.groups)) {
message(paste0("Applying function to ", u.groups[i], "."))
FUN(data[groups == u.groups[i],], name = u.groups[i], ...)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.