broom (version 0.4.1)

rowwise_df_tidiers: Tidying methods for rowwise_dfs from dplyr, for tidying each row and recombining the results

Description

These tidy, augment and glance methods are for performing tidying on each row of a rowwise data frame created by dplyr's group_by and do operations. They first group a rowwise data frame based on all columns that are not lists, then perform the tidying operation on the specified column. This greatly shortens a common idiom of extracting tidy/augment/glance outputs after a do statement.

Usage

"tidy"(x, object, ...)
"tidy_"(x, object, ...)
"augment"(x, object, ...)
"augment_"(x, object, ...)
"glance"(x, object, ...)
"glance_"(x, object, ...)
"tidy"(x, ...)
"augment"(x, ...)
"glance"(x, ...)

Arguments

x
a rowwise_df
object
the column name of the column containing the models to be tidied. For tidy, augment, and glance it should be the bare name; for _ methods it should be quoted.
...
additional arguments to pass on to the respective tidying method

Value

A "grouped_df", where the non-list columns of the original are used as grouping columns alongside the tidied outputs.

Details

Note that this functionality is not currently implemented for data.tables, since the result of the do operation is difficult to distinguish from a regular data.table.

Examples

Run this code

library(dplyr)
regressions <- mtcars %>%
    group_by(cyl) %>%
    do(mod = lm(mpg ~ wt, .))
 
regressions

regressions %>% tidy(mod)
regressions %>% augment(mod)
regressions %>% glance(mod)

# we can provide additional arguments to the tidying function
regressions %>% tidy(mod, conf.int = TRUE)

# we can also include the original dataset as a "data" argument
# to augment:
regressions <- mtcars %>%
    group_by(cyl) %>%
    do(mod = lm(mpg ~ wt, .), original = (.))

# this allows all the original columns to be included:
regressions %>% augment(mod)  # doesn't include all original
regressions %>% augment(mod, data = original)  # includes all original

Run the code above in your browser using DataCamp Workspace