rowwise_df_tidiers {broom} | R Documentation

## 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

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

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

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

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

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

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

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

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

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

### 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.

### Value

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

### Examples

    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

[Package broom version 0.4.1 Index]