Would something like this work?
library(tidyverse)
data <- tibble(
Name = c("Marc", "Carl", "Carl", "Carl", "Marc", "Max", "Max",
"Marc", "Carl", "Carl", "Carl", "Marc", "Max", "Max"),
Date = c(2006, 2003, 2002, 1990, 1999, 2016, 2014,
2006, 2003, 2002, 2019, 1999, 2016, 2014),
Second_Condition = c("a", "a", "a", "b", "b", "b", "b",
"a", "a", "b", "a", "b", "a", "b")
)
head(data)
# A tibble: 6 x 3
Name Date Second_Condition
<chr> <dbl> <chr>
1 Marc 2006 a
2 Carl 2003 a
3 Carl 2002 a
4 Carl 1990 b
5 Marc 1999 b
6 Max 2016 b
data %>%
mutate(Condition = if_else(Date > 2016, "After 2016", "Before 2016")) %>%
mutate_at(c("Name", "Condition", "Second_Condition"), as_factor) %>%
count(Name, Condition, Second_Condition, .drop = FALSE) %>%
pivot_wider(names_from = Second_Condition, values_from = n) %>%
mutate(Total = rowSums(select(., -c("Name", "Condition")), na.rm = TRUE))
# A tibble: 6 x 5
Name Condition a b Total
<fct> <fct> <int> <int> <dbl>
1 Marc Before 2016 2 2 4
2 Marc After 2016 0 0 0
3 Carl Before 2016 3 2 5
4 Carl After 2016 1 0 1
5 Max Before 2016 1 3 4
6 Max After 2016 0 0 0