Question:
Let’s say I have a dataframe where all columns are factors:
I’ve done this for a using the code (but I want to do this also for all the other columns b,c,d without replicating the code):
Answer:
What you probably first want to do is to transform your data in a tidy-format by usingpivot_longer
on a:d, and then group also by this variable, from there it is almost the same code as you wrote:If you have better answer, please add a comment about this, thank you!