
"print"(x, ...)
is.corpus(x)
is.corpuszip(x)
"+"(c1, c2)
"c"(..., recursive = FALSE)
"["(x, i, j = NULL, ..., drop = TRUE)
"[["(x, i, ...)
"[["(x, i) <- value
TRUE
, return a vector if extracting a single document
variable; if FALSE
, return it as a single-column data.frame. See
drop
for further details.is.corpus
returns TRUE
if the object is a corpusis.corpuszip
returns TRUE
if the object is a compressed corpus
+
operator for a corpus object will combine two corpus
objects, resolving any non-matching docvars
or
metadoc
fields by making them into NA
values for the
corpus lacking that field. Corpus-level meta data is concatenated, except
for source
and notes
, which are stamped with information
pertaining to the creation of the new joined corpus.
The `c()` operator is also defined for corpus class objects, and provides
an easy way to combine multiple corpus objects.
There are some issues that need to be addressed in future revisions of
quanteda concerning the use of factors to store document variables and
meta-data. Currently most or all of these are not recorded as factors,
because we use stringsAsFactors=FALSE
in the
data.frame
calls that are used to create and store the
document-level information, because the texts should always be stored as
character vectors and never as factors.
summary.corpus
# concatenate corpus objects
corpus1 <- corpus(data_char_inaugural[1:2])
corpus2 <- corpus(data_char_inaugural[3:4])
corpus3 <- corpus_subset(data_corpus_inaugural, President == "Obama")
summary(c(corpus1, corpus2, corpus3))
# ways to index corpus elements
data_corpus_inaugural["1793-Washington"] # 2nd Washington inaugural speech
data_corpus_inaugural[2] # same
# access the docvars from data_corpus_irishbudget2010
data_corpus_irishbudget2010[, "year"]
# same
data_corpus_irishbudget2010[["year"]]
# create a new document variable
data_corpus_irishbudget2010[["govtopp"]] <-
ifelse(data_corpus_irishbudget2010[["party"]] %in% c("FF", "Greens"),
"Government", "Opposition")
docvars(data_corpus_irishbudget2010)
Run the code above in your browser using DataLab