library(tidyverse)
set.seed(928)
ab <- tibble(
x = rbinom(100, 1, 0.5),
y = x + rnorm(100)
)
ab |>
summarise(
n_a = sum(x),
n_b = sum(1 - x),
estimate = sum(
(y * x) / n_a -
y * (1 - x) / n_b
)
)
# A tibble: 1 × 3
n_a n_b estimate
<int> <dbl> <dbl>
1 54 46 1.15