Tidyverse frequency tables are already clean, but you can enhance readability. For example, you might rename columns:
library(dplyr)
songs %>%
count(THEME) %>%
rename(
frequency = n,
music_theme = THEME
)
music_theme frequency
1 Heartbreak 145
2 Life_and_death 131
3 Love 139
4 Party_songs 162
5 People_and_places 145
6 Politics_and_protest 141
7 Sex 131
8 <NA> 6
Or format percentages neatly:
songs %>%
count(THEME) %>%
mutate(
percentage = paste(n / sum(n) * 100, "%")
) %>%
rename(
frequency = n,
music_theme = THEME
)
music_theme frequency percentage
1 Heartbreak 145 14.5 %
2 Life_and_death 131 13.1 %
3 Love 139 13.9 %
4 Party_songs 162 16.2 %
5 People_and_places 145 14.5 %
6 Politics_and_protest 141 14.1 %
7 Sex 131 13.1 %
8 <NA> 6 0.6 %
You can also pipe the result directly into knitr::kable() or gt::gt() to present the tables more professionally in papers or reports.
Back to top