Learn R Programming

broom (version 0.5.6)

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

Description

Rowwise tidiers are deprecated and will be removed from an upcoming version of broom. We strongly recommend moving to a nest-map-unnest workflow over a rowwise-do workflow. See the vignettes for examples.

Usage

# S3 method for rowwise_df
tidy(x, object, ...)

# S3 method for rowwise_df tidy_(x, object, ...)

# S3 method for rowwise_df augment(x, object, ...)

# S3 method for rowwise_df augment_(x, object, ...)

# S3 method for rowwise_df glance(x, object, ...)

# S3 method for rowwise_df glance_(x, object, ...)

# S3 method for tbl_df tidy(x, ...)

# S3 method for tbl_df augment(x, ...)

# S3 method for tbl_df 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

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.

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
# NOT RUN {
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 DataLab