Hello, while I found the table function useful for adhoc / interactive analysis, I usually don't like it in my workflows, i.e. scripts that do processes, because I find it annoying to work with the table output type.
Here is a version of code that is an alternative, avoiding 'table' but giving you counts for each round, for each type of round.
library(tidyverse)
cols<- 30
data <- sample(0:4, 600, TRUE) %>%
matrix(ncol = cols, byrow = TRUE) %>%
`colnames<-`(paste0("round_", str_pad(1:cols, 2, pad = "0"))) %>%
{cbind(participants = 1:20, .)} %>%
as.data.frame()
rounds_only <- data %>% select(starts_with("round"))
mapped_names <- names(rounds_only)
mapped <- map2(.x = rounds_only,
.y = mapped_names,
.f = ~enframe(x = .x,value = "round_base" ,name=NULL) %>% group_by_all() %>% count(name = paste0(.y,"_n")))
round_base <- list(tibble(round_base=0:4))
mapped2<- append(mapped,round_base,after=0)
final_result <- reduce(mapped2,.f=left_join)