◆ Glossary

R Function Definition
Encoding() checks or sets the encoding of a character string (base R)
as_tibble() converts a data frame into a tibble, which prints more neatly (tidyverse)
corpus() creates a quanteda corpus from a data frame, with text_field specifying the variable containing the texts (quanteda)
dfm() creates a document-feature matrix from tokens (quanteda)
dfm_tfidf() weights a document-feature matrix by tf-idf (quanteda)
dfm_weight() weights the cells of a document-feature matrix, e.g., as proportions with scheme = prop (quanteda)
docvars() shows the metadata (document variables) of a corpus, tokens object, or DFM (quanteda)
featnames() returns the names of all features in a document-feature matrix (quanteda)
filter() keeps only rows that meet a condition (tidyverse)
fixed() tells stringr functions to interpret a pattern literally instead of as a regular expression (stringr)
guess_encoding() guesses the encoding of a file (readr)
head() shows the first rows or elements of an object (base R)
install.packages() installs an R package (only needed once) (base R)
library() loads an installed R package (needed every time you restart R) (base R)
mutate() creates new variables or changes existing ones (tidyverse)
ncol() counts the number of columns of a data frame (base R)
ndoc() counts the number of documents in a corpus, tokens object, or DFM (quanteda)
nfeat() counts the number of features in a document-feature matrix (quanteda)
nrow() counts the number of rows of a data frame (base R)
ntoken() counts the number of tokens per document (quanteda)
phrase() declares a pattern as a multi-word expression, e.g., for tokens_compound() (quanteda)
pull() extracts a single variable from a data frame as a vector (tidyverse)
read.csv() reads in comma-separated .csv files (base R)
read.csv2() reads in semicolon-separated .csv files with commas as decimal separators (base R)
select() keeps only selected variables (tidyverse)
slice() keeps rows by their position, e.g., slice(1) for the first row (tidyverse)
sparsity() returns the share of cells in a document-feature matrix that contain a 0 (quanteda)
stopwords() returns a ready-made list of stopwords for a language, e.g., stopwords(english) (quanteda)
str_count() counts how often a pattern occurs in a text (stringr)
str_detect() checks whether a pattern occurs in a text (TRUE) or not (FALSE) (stringr)
str_extract() extracts the first match of a pattern (stringr)
str_length() counts the number of characters in a text (stringr)
str_remove_all() removes all occurrences of a pattern (stringr)
str_replace_all() replaces all occurrences of a pattern with something else (stringr)
summarise() calculates summary statistics, e.g., mean or maximum (tidyverse)
summary() gives an overview of a corpus, e.g., the number of tokens and types per document (quanteda)
tokens() tokenizes texts, i.e., breaks them down into features, and can remove punctuation, numbers, and symbols (quanteda)
tokens_compound() keeps multi-word expressions together as one feature, e.g., new_york (quanteda)
tokens_remove() removes features from tokens, e.g., stopwords (quanteda)
tokens_tolower() converts all tokens to lowercase (quanteda)
tokens_wordstem() reduces tokens to their word stem (quanteda)