I have a data that looks as follow:
toy.dat <- data.frame(group = c(rep("A_0", 3), rep("A_1", 2),
rep("B_0", 3) , rep("B_1", 3)))
toy.dat$letters <- c("A", 'B', "C", "A", "D", "C", "E", "F", "A", "B", "F")
toy.dat %>%
group_by(group) %>%
summarise(letters = list(letters), num = n()) %>%
mutate(group_number = gsub(".*_", "", group))
group letters num_elements group_num
A_0 c("A", "B", "C") 3 0
A_1 c("A", "D") 2 1
B_0 c("C", "E", "F") 3 0
B_1 c("A", "B", "F") 3 1
I would like to group by group_numb and find the intersection of letters of those rows and add them to the data frame.
the output should give "c" for A_0 and B_0 and "A" for A_1 and B_1.