I have a dataframe which consists of two columns with categorical variables (Better, Similar, Worse). I would like to come up with a table which counts the number of times that these categories appear in the two columns. The dataframe I am using is as follows:
Category.x Category.y
1 Better Better
2 Better Better
3 Similar Similar
4 Worse Similar
I would like to come up with a table like this:
Category.x Category.y
Better 2 2
Similar 1 2
Worse 1 0
How would you go about it?
table(df1)
– Advancementfactor
with commonlevels
lvls <- unique(unlist(df1)); df1[] <- lapply(df1, factor, levels = lvls)
and then do thetable(df1)
– Advancement