whence_group() takes a table from whence_table() and the number of a
row. It gives a trace of that row: for each step, how many rows of its
group were left, and how many the step removed. Use whence_rows() on it
for the rows of the group, or for the rows of the group that one step
removed.
Arguments
- table
A
whence_tablefromwhence_table().- ...
The values of the group columns of the row, by name, such as
region = "APAC". They must find exactly one row. A single number without a name is the number of the row.- row
The number of a row of the table. Give
row, or the group values in....
Value
A whence_group object, which is also a whence_trace. Its value
is the row, as a data frame with one row.
Details
The counts come from a replay of the steps with a hidden id column. After
a step that breaks the link between a row and the source, such as
distinct(), the counts of the group are not known, and the trace says
so. The reproduce code is the code of the table with a last filter()
that keeps this row, so it gives the row as the table has it.
Examples
library(dplyr, warn.conflicts = FALSE)
by_cyl <- whence_table(
mtcars |>
filter(hp > 90) |>
count(cyl)
)
six <- whence_group(by_cyl, 2)
six
#> <whence_group> cyl = 6
#>
#> Where the rows went
#> 0 mtcars 7
#> 1 -> hp > 90 7
#> 2 -> summarised into this row 1
#>
#> Reproduce
#> mtcars |>
#> filter(hp > 90) |>
#> count(cyl) |>
#> filter(cyl == 6)
whence_rows(six)
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
#> Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
#> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
#> Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
#> Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
#> Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
#> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6
# The same row, by its group
whence_group(by_cyl, cyl = 6)
#> <whence_group> cyl = 6
#>
#> Where the rows went
#> 0 mtcars 7
#> 1 -> hp > 90 7
#> 2 -> summarised into this row 1
#>
#> Reproduce
#> mtcars |>
#> filter(hp > 90) |>
#> count(cyl) |>
#> filter(cyl == 6)
