Learn R Programming

metan (version 1.19.0)

doo: Alternative to dplyr::do for doing anything

Description

Provides an alternative to the dplyr:do() using nest(), mutate() and map() to apply a function to a grouped data frame.

Usage

doo(.data, .fun, ..., unnest = TRUE)

Value

a data frame

Arguments

.data

a (grouped) data frame

.fun

A function, formula, or atomic vector.

...

Additional arguments passed on to .fun

unnest

Logical argument defaults to TRUE to control if results of .fun should be unnested. Valid only if the result is of class data.frame or tbl_df.

Author

Tiago Olivoto tiagoolivoto@gmail.com

Details

If the applied function returns a data frame, then the output will be automatically unnested. Otherwise, the output includes the grouping variables and a column named "data" , which is a "list-columns" containing the results for group combinations.

Examples

Run this code
# \donttest{
library(metan)
# Head the first two lines of each environment
data_ge2 %>%
 group_by(ENV) %>%
 doo(~head(., 2))

# Genotype analysis for each environment using 'gafem()'
# variable PH
data_ge2 %>%
  group_by(ENV) %>%
  doo(~gafem(., GEN, REP, PH, verbose = FALSE))
# }

Run the code above in your browser using DataLab