keep_dimensions: Keep dimensions

Description Usage Arguments See Also Examples

View source: R/dimensions.R

Description

This function keeps specified dimensions from a wide metric tbl and discards the rest.

Usage

1
keep_dimensions(tbl, ..., keep_attribute_all = FALSE, quietly = FALSE)

Arguments

tbl

A metric tbl in wide format, with one or more dimensions.

...

Dimensions to keep, as bare names or select helpers like contains().

keep_attribute_all

Whether to remove the "All" level from the dimensions

quietly

If FALSE (default), display a message about what columns are being discarded.

See Also

discard_dimensions()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
library(dplyr)

mtcars_by_cyl_gear <- mtcars %>%
  cross_by_dimensions(cyl, gear) %>%
  summarize(avg_mpg = mean(mpg))

mtcars_by_cyl_gear %>%
  keep_dimensions()

mtcars_by_cyl_gear %>%
  keep_dimensions(cyl)

mtcars_by_cyl_gear %>%
  keep_dimensions(-cyl)

mtcars_by_cyl_gear %>%
  keep_dimensions(cyl, keep_attribute_all = TRUE)

datacamp/tidymetrics documentation built on March 21, 2021, 3:28 a.m.