ndoc: Count the number of documents or features

Description Usage Arguments Details Value See Also Examples

View source: R/nfunctions.R

Description

Get the number of documents or features in an object.

Usage

1
2
3
ndoc(x)

nfeat(x)

Arguments

x

a quanteda object: a corpus, dfm, or tokens object, or a readtext object from the readtext package.

Details

ndoc returns the number of documents in an object whose texts are organized as "documents" (a corpus, dfm, or tokens object, a readtext object from the readtext package).

nfeat returns the number of features from a dfm; it is an alias for ntype when applied to dfm objects. This function is only defined for dfm objects because only these have "features". (To count tokens, see ntoken().)

Value

an integer (count) of the number of documents or features

See Also

ntoken()

Examples

1
2
3
4
5
6
7
8
9
# number of documents
ndoc(data_corpus_inaugural)
ndoc(corpus_subset(data_corpus_inaugural, Year > 1980))
ndoc(tokens(data_corpus_inaugural))
ndoc(dfm(corpus_subset(data_corpus_inaugural, Year > 1980)))

# number of features
nfeat(dfm(corpus_subset(data_corpus_inaugural, Year > 1980), remove_punct = FALSE))
nfeat(dfm(corpus_subset(data_corpus_inaugural, Year > 1980), remove_punct = TRUE))

koheiw/quanteda.core documentation built on Sept. 21, 2020, 3:44 p.m.