I have a table like this :
Menu name | Transcode
Menu 1 | a1
Menu 2 | a2
Menu 3 | a3
Menu 1 | a1
Menu 3 | a2
Menu 1 | a1
Menu 1 | a3
How can I achieve this pivot in R. to count the number of values frequency in column x (menu name) and the frequency of column y (Trancode) in relation with column x
Instead of a two column output, it may be better to have it in three columns (for easier post-processing). We get the frequency counts using
table
, useaddmargins
tosum
up the counts for each "Menu_name", convert to 'data.frame'. If needed, we canorder
the output ('res') by the first column.Then, use
rbind
to create the "Grand Sum" row