Learn R Programming

quanteda (version 0.9.9-3)

ndoc: count the number of documents or features

Description

Get the number of documents, tokens, types, or features in an object.

Usage

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 in the corpus or dfm

Details

ndoc returns the number of documents or features in a quanteda object.

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

Run this code
# 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
nfeature(dfm(corpus_subset(data_corpus_inaugural, Year > 1980), removePunct = FALSE))
nfeature(dfm(corpus_subset(data_corpus_inaugural, Year > 1980), removePunct = TRUE))

Run the code above in your browser using DataLab