These perform set operations on tracked dataframes. It merges the history
of 2 (or more) dataframes and combines the rows (or columns). It calculates the total number of
resulting rows as {.count.out} in other terms it performs exactly the same
operation as the equivalent dplyr
operation. See dplyr::bind_rows()
,
dplyr::bind_cols()
, dplyr::intersect()
, dplyr::union()
,
dplyr::setdiff()
,dplyr::intersect()
, or dplyr::union_all()
for the
underlying function details.
Usage
# S3 method for class 'trackr_df'
intersect(
x,
y,
...,
.messages = "{.count.out} in intersection",
.headline = "Intersection"
)
Examples
library(dplyr)
library(dtrackr)
# Set operations
people = starwars %>% select(-films, -vehicles, -starships)
chrs = people %>% track("start")
lhs = chrs %>% include_any(
species == "Human" ~ "{.included} humans",
species == "Droid" ~ "{.included} droids"
)
# these are different subsets of the same data
rhs = chrs %>% include_any(
species == "Human" ~ "{.included} humans",
species == "Gungan" ~ "{.included} gungans"
) %>% comment("{.count} gungans & humans")
# Unions
set = bind_rows(lhs,rhs) %>% comment("{.count} 2*human,droids and gungans")
# display the history of the result:
set %>% history()
#> dtrackr history:
#> number of flowchart steps: 3 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> └ "79 2*human,droids and gungans"
nrow(set)
#> [1] 79
# not run - display the flowchart:
# set %>% flowchart()
set = union(lhs,rhs) %>% comment("{.count} human,droids and gungans")
# display the history of the result:
set %>% history()
#> dtrackr history:
#> number of flowchart steps: 5 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> └ "44 human,droids and gungans"
nrow(set)
#> [1] 44
# not run - display the flowchart:
# set %>% flowchart()
set = union_all(lhs,rhs) %>% comment("{.count} 2*human,droids and gungans")
# display the history of the result:
set %>% history()
#> dtrackr history:
#> number of flowchart steps: 5 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> └ "79 2*human,droids and gungans"
nrow(set)
#> [1] 79
# not run - display the flowchart:
# set %>% flowchart()
# Intersections and differences
set = setdiff(lhs,rhs) %>% comment("{.count} droids and gungans")
# display the history of the result:
set %>% history()
#> dtrackr history:
#> number of flowchart steps: 5 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> └ "6 droids and gungans"
nrow(set)
#> [1] 6
# not run - display the flowchart:
# set %>% flowchart()
set = intersect(lhs,rhs) %>% comment("{.count} humans")
# display the history of the result:
set %>% history()
#> dtrackr history:
#> number of flowchart steps: 5 (approx)
#> tags defined: <none>
#> items excluded so far: <not capturing exclusions>
#> last entry / entries:
#> └ "35 humans"
nrow(set)
#> [1] 35
# not run - display the flowchart:
# set %>% flowchart()