I have several different datasets with different number of factor variables and an output variable. For each of these data-set I need to find number of rows of observations grouped by each factor level of the variables and further grouped by all variables (columns). I thought a for loop might do the trick but am struggling with it. Could someone please help with this?

the data set looks something like this:

[enter image description here](https://i.stack.imgur.com/Obhxk.png)

and I want the ouput to be 
[enter image description here](https://i.stack.imgur.com/gNxWz.png)

I have tried 

```
for (i in 1:length(df)){
df %>% group_by(df[[i]]) %>%  summarise(n = length(i))%>%print()

```

}

but this doesn't seem to be working