Exclude columns matching a pattern and the resulting duplicates
See also
Other helpers:
jitter_range()
,
join_to()
,
summarize_range()
,
unnest_product()
Examples
library(tibble)
# Excludes columns along with all its duplicates
data <- tibble(x = 1, y = 1:2)
data
#> # A tibble: 2 × 2
#> x y
#> <dbl> <int>
#> 1 1 1
#> 2 1 2
data |> exclude("y")
#> # A tibble: 1 × 1
#> x
#> <dbl>
#> 1 1
# Columns are matched as a regular expression
data <- tibble(x = 1, yz = 1:2, zy = 1)
data
#> # A tibble: 2 × 3
#> x yz zy
#> <dbl> <int> <dbl>
#> 1 1 1 1
#> 2 1 2 1
data |> exclude("y")
#> # A tibble: 1 × 1
#> x
#> <dbl>
#> 1 1
data |> exclude("y$")
#> # A tibble: 2 × 2
#> x yz
#> <dbl> <int>
#> 1 1 1
#> 2 1 2
# With a 'tilt_profile' excludes at both levels in a single step
product <- company <- tibble(companies_id = 1, y = "a", z = 1)
result <- tilt_profile(nest_levels(product, company))
result |> class()
#> [1] "tilt_profile" "tbl_df" "tbl" "data.frame"
result
#> # A tibble: 1 × 3
#> companies_id product company
#> * <dbl> <list> <list>
#> 1 1 <tibble [1 × 2]> <tibble [1 × 2]>
out <- result |> exclude("y")
out |> unnest_product()
#> # A tibble: 1 × 2
#> companies_id z
#> <dbl> <dbl>
#> 1 1 1
out |> unnest_company()
#> # A tibble: 1 × 2
#> companies_id z
#> <dbl> <dbl>
#> 1 1 1