| add_count.corpus | R Documentation |
add_count() and add_tally() are wrappers around dplyr::add_count() and
dplyr::add_tally() that add a new document variable with the number of
observations. add_count() is a shortcut for group_by() + add_tally().
## S3 method for class 'corpus'
add_count(x, ..., wt = NULL, sort = FALSE, name = NULL, .drop = NULL)
## S3 method for class 'corpus'
add_tally(x, ..., wt = NULL, sort = FALSE, name = NULL)
x |
a quanteda corpus object |
... |
for |
wt |
frequency weights. Can be
|
sort |
if |
name |
the name of the new column in the output. If omitted, it will
default to |
.drop |
not used for corpus objects; included for compatibility with the generic |
a corpus with an additional document variable containing counts
# Count documents by President and add as a variable
data_corpus_inaugural %>%
add_count(President) %>%
summary(n = 10)
# Add total count to each document
data_corpus_inaugural %>%
head() %>%
add_tally() %>%
summary()
# Count by multiple variables
data_corpus_inaugural %>%
add_count(Party, President) %>%
summary(n = 10)
# Use custom name
data_corpus_inaugural %>%
add_count(Party, name = "party_count") %>%
summary(n = 10)
# Add tally to show total count
data_corpus_inaugural %>%
slice(1:6) %>%
add_tally() %>%
summary()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.