Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

new_grouped_df

Low-level construction and validation for the grouped_df class


Description

new_grouped_df() is a constructor designed to be high-performance so only check types, not values. This means it is the caller's responsibility to create valid values, and hence this is for expert use only.

validate_grouped_df() validates the attributes of a grouped_df.

Usage

new_grouped_df(x, groups, ..., class = character())

validate_grouped_df(x, check_bounds = FALSE)

Arguments

x

A data frame

groups

The grouped structure, groups should be a data frame. Its last column should be called .rows and be a list of 1 based integer vectors that all are between 1 and the number of rows of .data.

...

additional attributes

class

additional class, will be prepended to canonical classes of a grouped data frame.

check_bounds

whether to check all indices for out of bounds problems in grouped_df objects

Examples

# 5 bootstrap samples
tbl <- new_grouped_df(
  tibble(x = rnorm(10)),
  groups = tibble(".rows" := replicate(5, sample(1:10, replace = TRUE), simplify = FALSE))
)
# mean of each bootstrap sample
summarise(tbl, x = mean(x))

dplyr

A Grammar of Data Manipulation

v1.0.6
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre] (<https://orcid.org/0000-0003-4757-117X>), Romain François [aut] (<https://orcid.org/0000-0002-2444-4226>), Lionel Henry [aut], Kirill Müller [aut] (<https://orcid.org/0000-0002-1416-3412>), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.