solve most of predefined challenges

This commit is contained in:
2021-08-02 16:12:18 +02:00
parent d01cea9d52
commit 4fe45feec9
7 changed files with 138 additions and 24 deletions
+19
View File
@@ -29,3 +29,22 @@ bar_plot_fraktionen <- function(tb) {
scale_fill_manual(values = party_colors) +
geom_bar(stat = "identity")
}
# Counts how many talks do match a given pattern and summarises by date
#
#' @export
word_usage_by_date <- function(res, patterns, name, tidy=F) {
tb <- res$talks
nms <- names(patterns)
for (i in seq_along(patterns)) {
if (!is.null(nms)) name <- nms[[i]]
else name <- patterns[[i]]
tb <- mutate(tb, {{name}} := str_count(content, patterns[[i]]))
}
left_join(tb, res$reden, by=c("rede_id" = "id")) %>%
group_by(date) %>%
summarize(across(where(is.numeric), sum)) %>%
arrange(date) -> tb
if (!tidy) pivot_longer(tb, where(is.numeric) , names_to = "pattern", values_to="count")
else tb
}