frequencies <- table(songs$THEME,
exclude = NULL)
proportions <- prop.table(frequencies)
cum_proportions <- cumsum(proportions)
percentages <- prop.table(frequencies)*100
cum_percentages <- cumsum(percentages)Making Readable Tables
We have now retrieved various tables (frequencies, proportions, percentages, and the cumulative sum), and we can extract the information we need from them, but they are not very readable.
We can also combine these different options in R into a single table. We will do this for the variable THEME. To do this, we first create all the separate tables and give them clear names:
Then we can combine these tables using the cbind() function. This ensures that each separate table fills one column in the combined table.
cbind(frequencies,
percentages,
cum_percentages,
proportions,
cum_proportions) frequencies percentages cum_percentages proportions
Heartbreak 145 14.5 14.5 0.145
Life_and_death 131 13.1 27.6 0.131
Love 139 13.9 41.5 0.139
Party_songs 162 16.2 57.7 0.162
People_and_places 145 14.5 72.2 0.145
Politics_and_protest 141 14.1 86.3 0.141
Sex 131 13.1 99.4 0.131
<NA> 6 0.6 100.0 0.006
cum_proportions
Heartbreak 0.145
Life_and_death 0.276
Love 0.415
Party_songs 0.577
People_and_places 0.722
Politics_and_protest 0.863
Sex 0.994
<NA> 1.000
Now we have everything clearly arranged side by side!
Back to top