For a dfm object, returns the first or last n documents and first nfeature features for inspection.

# S3 method for dfm
head(x, n = 6L, nfeature = 6L, ...)

# S3 method for dfm
tail(x, n = 6L, nfeature = 6L, ...)

Arguments

x

a dfm object

n

a single integer. If positive, size for the resulting object: number of first/last documents for the dfm. If negative, all but the n last/first number of documents of x.

nfeature

the number of features to return, where the resulting object will contain the first ncol features

...

additional arguments passed to other functions

Value

A dfm class object corresponding to the subset defined by n and nfeature.

Examples

myDfm <- dfm(data_corpus_inaugural, ngrams = 2, verbose = FALSE) head(myDfm)
#> Document-feature matrix of: 58 documents, 63,597 features (96.9% sparse). #> (showing first 6 documents and first 6 features) #> features #> docs fellow-citizens_of of_the the_senate senate_and and_of #> 1789-Washington 1 20 1 1 2 #> 1793-Washington 0 4 0 0 1 #> 1797-Adams 0 29 0 0 2 #> 1801-Jefferson 0 28 0 0 3 #> 1805-Jefferson 0 17 0 0 1 #> 1809-Madison 0 20 0 0 2 #> features #> docs the_house #> 1789-Washington 2 #> 1793-Washington 0 #> 1797-Adams 0 #> 1801-Jefferson 0 #> 1805-Jefferson 0 #> 1809-Madison 0
tail(myDfm)
#> Document-feature matrix of: 58 documents, 63,597 features (96.9% sparse). #> (showing last 6 documents and last 6 features) #> features #> docs fellow-citizens_of of_the the_senate senate_and and_of the_house #> 1997-Clinton 0 11 0 0 0 0 #> 2001-Bush 0 2 0 0 0 0 #> 2005-Bush 0 14 0 0 0 0 #> 2009-Obama 0 4 0 0 0 0 #> 2013-Obama 0 2 0 0 0 0 #> 2017-Trump 0 3 0 0 0 0
tail(myDfm, nfeature = 4)
#> Document-feature matrix of: 58 documents, 63,597 features (96.9% sparse). #> (showing last 6 documents and last 4 features) #> features #> docs fellow-citizens_of of_the the_senate senate_and #> 1997-Clinton 0 11 0 0 #> 2001-Bush 0 2 0 0 #> 2005-Bush 0 14 0 0 #> 2009-Obama 0 4 0 0 #> 2013-Obama 0 2 0 0 #> 2017-Trump 0 3 0 0