knitr::opts_chunk$set( collapse = TRUE, comment = "##", fig.path = "man/images/" )
library("badger")
r badge_devel("quanteda/quanteda.tidy", "royalblue")
quanteda.tidy extends the quanteda package with functionality from the "tidyverse", especially dplyr.
Note that this is not the same as tidytext, which stretches tokens into data.frames. Instead, tidy functions operate only on document variables, but extends these functions (from dplyr) to work on quanteda objects as if they were tibbles or data.frames.
You can install quanteda.tidy from GitHub with:
devtools::install_github("quanteda/quanteda.tidy")
Adding a document variable for full president name:
library("quanteda.tidy", warn.conflicts = FALSE) data_corpus_inaugural %>% transmute(fullname = paste(FirstName, President, sep = ", ")) %>% summary(n = 5) data_corpus_inaugural %>% mutate(fullname = paste(FirstName, President, sep = ", ")) %>% summary(n = 5)
Filtering documents based on years:
data_corpus_inaugural %>% filter(President == "Roosevelt") %>% summary()
Renaming document variables:
data_corpus_inaugural %>% rename(LastName = President) %>% select(FirstName, LastName) %>% summary(n = 5)
Glimpse (from tibble):
glimpse(data_corpus_inaugural)
Slice operations:
slice(data_corpus_inaugural, 1:3) slice_head(data_corpus_inaugural, prop = .10) slice_tail(data_corpus_inaugural, n = 3) set.seed(42) slice_sample(data_corpus_inaugural, prop = .50)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.