solve most of predefined challenges
This commit is contained in:
+19
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user