my data.frame:

```
data<-structure(list(GROUP = c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L), 
                     col1 = c(23L, 432L, 234L, 234L, 3123L, 657L,
                              8768L, 123L,42323L), 
                     col2 = c(567L, 765L, 8678L, 46L, 35L, 24L, 76L, 
                              789L, 45L), 
                     col3 = c(1L, 3L, 5L, 7L, 8L, 0L, 8L, 7L, 3L), 
                     col4 = c("S", "S", "S", "S", "F", "F", "F", 
                              "F", "F"), 
                     col5 = c("a","a", "s", "s", "s", "s", "s", 
                              "s", "s")
               ), class = "data.frame", row.names = c(NA,-9L))

```

Function:

```
combination = list(c(2,3),c(3,4),c(5,6))
    wilcox.fun <- function(df, id_group){
      df = df[df$GROUP%in%id_group,]
      x <- function(dat) { 
        do.call(rbind, lapply(combination, function(x) {
          col1 <- dat[[x[1]]]
          col2 <- dat[[x[2]]]
          if(is.numeric(col1) && is.numeric(col2)) test <- wilcox.test(col1, col2)
          else  test <- fisher.test(col1, col2)
          data.frame(Test = sprintf('Group %s by Group %s Group',x[1],x[2]), 
                     p = test$p.value,
                     col <- paste(x[1],unique(dat[[x[1]]]),unique(table(dat[[x[1]]])),":",x[2],unique(dat[[x[2]]]),unique(table(dat[[x[2]]])))
          )
        }))
      }
      return (purrr::map_df(split(df, df$GROUP),x,.id="GROUP" ))
    }

    wilcox.fun(data, c(1, 2))

```

I want to calculate for each value from the columns their number by groups.

For example, for the column `col4`, the number of "S" in group 1 = 2. In group 2, the number of " S " = 2. In group 1, the number of " F " = 3. In group 2, the number of " F " = 2 and so on

I tried using the `table` function, but it outputs too many repeating combinations.