---
title: "Texts, Functions, and Probabilities problems"
output: word_document
...

```{r, include = FALSE}
library(tidyverse)
library(HumanitiesDataAnalysis)
knitr::opts_chunk$set(eval=FALSE)
```

<h2 id="exercises">Exercises</h2>
<p><a href="extracted_problem_sets/7-Texts.Rmd" download="7-Texts.Rmd">Download these problems</a></p>
<h3 id="state-of-the-union">State of the Union</h3>
<p>Let’s review some visualization, filtering, and grouping functions using State of the Union Addresses. This initial block should get you started with state of the Union Addresses</p>
<ol type="1">
<li>What is the first word of the 7th paragraph of the 1997 State of the Union Address?</li>
</ol>
<p>```{r class.source = “answers”, eval = FALSE}</p>
<p>allSOTUs %&gt;% filter(paragraph == 7, year == 1997)</p>
<ol start="3" type="1">
<li>What context was that first use?</li>
</ol>
<p>```{r class.source = “answers”, eval = FALSE}</p>
<p>allSOTUs %&gt;% filter(paragraph == 39, year == 1825)</p>
<p>```{r class.source = “answers”, eval = FALSE}</p>
<p>allSOTUs %&gt;% filter (sotu_type == “speech”) %&gt;% group_by(president) %&gt;% summarize(count = n()) %&gt;% arrange(-count)</p>
<p>HumanitiesDataAnalysis::books %&gt;% filter(subjects %&gt;% str_detect(“Genocide”))</p>
<p><code>{r class.source = "answers", eval = FALSE} allSOTUs %&gt;%    filter (sotu_type == "speech") %&gt;%   group_by(president, year) %&gt;%    summarize(count = n()) %&gt;%   group_by(president) %&gt;%    summarize(average_length = mean(count)) %&gt;%   arrange(average_length)</code></p>
<ol start="6" type="1">
<li>Make a plot of the data from the previous answer.</li>
</ol>
<p>```{r class.source = “answers”, eval = FALSE}</p>
<p>allSOTUs %&gt;% filter (sotu_type == “speech”) %&gt;% group_by(president, year, party) %&gt;% summarize(count = n()) %&gt;% group_by(president, party) %&gt;% summarize(average_length = mean(count)) %&gt;% arrange(average_length) %&gt;% ggplot() + geom_col() + aes(x=president, y = average_length, fill=party) + coord_flip()</p>
<p>```{r class.source = “answers”, eval = FALSE}</p>
<p>totals = allSOTUs %&gt;% group_by(year) %&gt;% summarize(total_words = n())</p>
<p>```{r class.source = “answers”, eval = FALSE}</p>
<p>military_counts = allSOTUs %&gt;% filter(word %in% c(“army”, “navy”, “marines”, “forces”)) %&gt;% group_by(year) %&gt;% summarize(count=n())</p>
<p>military_counts %&gt;% inner_join(totals) %&gt;% ggplot() + geom_line(aes(x=year, y=count/total_words))</p>
<h3 id="free-exercise">Free Exercise</h3>
<p>Fill a folder with text files of your own. Read them in, and plot the usage of some words by location, paragraph, or something else. Use a different foldername than “SOTUS” below: but do move it into your personal R folder.</p>
<p><code>{r eval=FALSE} all_my_files = list.files("SOTUS", full.names = TRUE) %&gt;%   map_dfr(read_tokens) %&gt;%   KEEP_GOING</code></p>
