forked from quanteda/quanteda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocvars.Rd
51 lines (45 loc) · 1.66 KB
/
docvars.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/docvars.R
\name{docvars}
\alias{docvars}
\alias{docvars<-}
\title{Get or set document-level variables}
\usage{
docvars(x, field = NULL)
docvars(x, field = NULL) <- value
}
\arguments{
\item{x}{\link{corpus}, \link{tokens}, or \link{dfm} object whose
document-level variables will be read or set}
\item{field}{string containing the document-level variable name}
\item{value}{the new values of the document-level variable}
}
\value{
\code{docvars} returns a data.frame of the document-level variables,
dropping the second dimension to form a vector if a single docvar is
returned.
\code{docvars<-} assigns \code{value} to the named \code{field}
}
\description{
Get or set variables associated with a document in a \link{corpus},
\link{tokens} or \link{dfm} object.
}
\note{
Reassigning document variables for a \link{tokens} or \link{dfm} object
is allowed, but discouraged. A better, more reproducible workflow is to
create your docvars as desired in the \link{corpus}, and let these continue
to be attached "downstream" after tokenization and forming a document-feature
matrix. Recognizing that in some cases, you may need to modify or add
document variables to downstream objects, the assignment operator is defined
for \link{tokens} or \link{dfm} objects as well. Use with caution.
}
\examples{
# retrieving docvars from a corpus
head(docvars(data_corpus_inaugural))
tail(docvars(data_corpus_inaugural, "President"), 10)
# assigning document variables to a corpus
corp <- data_corpus_inaugural
docvars(corp, "President") <- paste("prez", 1:ndoc(corp), sep = "")
head(docvars(corp))
}
\keyword{corpus}