Count the Words SOCL 3633 Research Methods · Lab 15 · Midwestern State University
On Tuesday you read ten court texts and coded them by hand. Today the computer reads all twenty. You count every word in the shared corpus, chart the most frequent ones, and then give the computer a short word list for one of your codes, so it codes the same ten texts as a second coder. Keep this page open next to RStudio, have your Tuesday coding grid in front of you, and work through the tabs in order. Submit your response sheet and your chart in the Lab 15 submission on D2L by Thursday, April 29, at 11:59 p.m.
Get set up
nrow(corpus) prints 20, one row for each text.If you missed Tuesday or lost your grid
Code the ten texts (1, 2, 3, 5, 8, 9, 10, 11, 12, and 17) for one code before Step 5: hiding or concealment, defined as "the text describes a step taken to hide the conduct or avoid detection." Write 1 or 0 for each text. It takes about ten minutes with the handout.
If something goes wrong
| What you see | What to do |
|---|---|
| "class_corpus.csv does not exist in current working directory" | The file is in a different folder, or its name is different. Check the Files pane. Then click Session, Set Working Directory, To Source File Location, and run Step 1 again. |
| "there is no package called 'tidytext'" | Run Step 0 again and wait for it to finish. If it still fails, tell your instructor. |
| "Existing data has 10 rows. Assigned data has 9 rows." (or another number) | Your my_codes line in Step 5 does not have exactly ten values. Count them against your grid and run it again. |
A + sign in the Console | A parenthesis or quotation mark is missing. Press Escape in the Console, fix the line, and run it again. |
Count the words: Steps 2 and 3
Step 2: one row per word
Put text in the blank in unnest_tokens(word, ____) and run the lines, then nrow(words).
nrow(words) prints 1097: the 20 texts hold 1,097 words.Step 3: count the words
Run count(words, word, sort = TRUE). The top of the list is "the," "to," and "a." These are stop words: words that hold sentences together but say little about the topic. Run the anti_join(stop_words, ...) lines to remove them, then count again.
Chart them: Step 4
- Run the
top_wordslines. They keep every word that appears at least 4 times. - Run the chart lines and
print(words_chart). - Replace the title with a short complete sentence, about ten words, that says what the words show. Run the chart lines again.
- In the
ggsave()line, replacelastnamewith your last name and run it.
A word list as a second coder: Step 5
A content dictionary is a list of words that stand for one idea. The computer marks a text 1 if any word on the list appears in it, and 0 if none does. Today's list is for hiding or concealment.
- Run the
ten,my_words, andpatternlines, then theflagslines, thenflags. Theword_listcolumn shows the computer's call for each of the ten texts. - Find the column on your Tuesday grid for the code closest to hiding or concealment. In the
my_codes <- c(____)blank, type its ten values, 1 or 0, separated by commas, in grid order. Run it, then the next two lines. - Run
sum(flags$word_list == flags$my_code): the number of texts, out of 10, where you and the word list agree. - Add one word beginning to
my_wordsthat you think the list is missing, such as"evad"or"avoid". Run Step 5 again from themy_wordsline and see whether the count changes.
my_words with four to six word beginnings you think signal it. Say which code you chose in question 4.Lab 15 response sheet
Answer in complete sentences. Then assemble your answers and paste them into the Lab 15 submission on D2L. In the same submission, upload your chart picture. Both are due Thursday, April 29, at 11:59 p.m.
Sources
Silge, Julia, and David Robinson. 2016. "tidytext: Text Mining and Analysis Using Tidy Data Principles in R." Journal of Open Source Software 1(3):37.
Wickham, Hadley. 2016. ggplot2: Elegant Graphics for Data Analysis. New York: Springer.
The corpus: 20 short excerpts from public federal court records in fraud cases, retrieved from CourtListener (courtlistener.com) on October 1, 2026. Full citations for each text are at the end of the Shared Corpus handout.