Get the number of documents or features in an object.

ndoc(x)

nfeature(x)

Arguments

x

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

Value

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

Details

ndoc returns the number of documents in a corpus, dfm, or tokens object, or a readtext object from the readtext package

nfeature returns the number of features in a dfm nfeature 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.)

See also

ntoken

Examples

# number of documents ndoc(data_corpus_inaugural)
#> [1] 58
ndoc(corpus_subset(data_corpus_inaugural, Year > 1980))
#> [1] 10
ndoc(tokens(data_corpus_inaugural))
#> [1] 58
ndoc(dfm(corpus_subset(data_corpus_inaugural, Year > 1980)))
#> [1] 10
# number of features nfeature(dfm(corpus_subset(data_corpus_inaugural, Year > 1980), remove_punct = FALSE))
#> [1] 3260
nfeature(dfm(corpus_subset(data_corpus_inaugural, Year > 1980), remove_punct = TRUE))
#> [1] 3247