Adapted from Section 3 of https://cran.r-project.org/web/packages/data.table/vignettes/datatable-secondary-indices-and-auto-indexing.html:
library(data.table)
set.seed(1L)
dt1 = data.table(x = sample(1:2, 10, TRUE), y = runif(10L))
set.seed(1L)
dt2 = data.table(x = sample(1:2, 10, TRUE), y = runif(10L))
waldo::compare(dt1, dt2)
#> ✓ No differences
dt1[x == 1L]
#> x y
#> 1: 1 0.2059746
#> 2: 1 0.6870228
#> 3: 1 0.3841037
#> 4: 1 0.4976992
#> 5: 1 0.7176185
#> 6: 1 0.9919061
waldo::compare(dt1, dt2)
#> `attr(old, 'index')` is an integer vector ()
#> `attr(new, 'index')` is absent
Created on 2021-09-16 by the reprex package (v2.0.1)