gapply.groupr: Perform function(s) on grouping object.

Description Usage Arguments Examples

Description

Given a metric calculated using a groupr object, one could need to perform additional analysis using the data produced. For example, a groupr object could be used to count the number of employees in an organization and get their total tenure, as broken out by various groups (state, full/part time, etc.). A natural, additional calculation could be an total tenure divided by count. This function is generalized so that any function with one argument (df) can be passed.

Usage

1
2
## S3 method for class 'groupr'
gapply(groupr, new_functions, is_cbind = F)

Arguments

groupr

A grouping object created with the function

new_functions

A list of functions (each with one argument: df) to apply to the grouping object. The df argument will be the dataframe in the grouping object.

is_cbind

Boolean value for whether or not the functions applied should be added to the df passed, or if they should be returned as a list (with similar dimensions as the groupr)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
permits_groupr <- groupr(
  permits,
  groups = c("type_desc", "issued_date", "existing_const_type")
)
extract_df(permits_groupr, "existing_const_type")
applied_groupr <- gapply(permits_groupr,
  list(rounded = function(df) round(df$count, -2)),
  is_cbind = TRUE
)
extract_df(applied_groupr, "existing_const_type")

athompson1991/groupR documentation built on May 10, 2019, 2:09 p.m.