Learn R Programming

quanteda (version 0.9.8.5)

docvars: get or set for document-level variables

Description

Get or set variables for the documents in a corpus

Usage

docvars(x, field = NULL)
"docvars"(x, field = NULL)
docvars(x, field = NULL) <- value
"docvars"(x, field = NULL) <- value
"docvars"(x, field = NULL)

Arguments

x
corpus whose document-level variables will be read or set
field
string containing the document-level variable name
value
the new values of the document-level variable

Value

docvars returns a data.frame of the document-level variablesdocvars<- assigns value to the named field

Examples

Run this code
head(docvars(inaugCorpus))
docvars(inaugCorpus, "President") <- paste("prez", 1:ndoc(inaugCorpus), sep="")
head(docvars(inaugCorpus))

# alternative using indexing
head(inaugCorpus[, "Year"])
inaugCorpus[["President2"]] <- paste("prezTwo", 1:ndoc(inaugCorpus), sep="")
head(docvars(inaugCorpus))

Run the code above in your browser using DataLab