Methods for coercing a dfm object to a matrix or data.frame object.

# S3 method for dfm
as.matrix(x, ...)

# S3 method for dfm
as.data.frame(x, row.names = NULL, ...)

Arguments

x

dfm to be coerced

...

unused

row.names

if FALSE, do not set the row names of the data.frame to the docnames of the dfm (default); or a vector of values to which the row names will be set.

Examples

# coercion to matrix mydfm <- dfm(data_corpus_inaugural) str(as.matrix(mydfm))
#> num [1:58, 1:9357] 1 0 3 2 0 1 1 5 1 0 ... #> - attr(*, "dimnames")=List of 2 #> ..$ docs : chr [1:58] "1789-Washington" "1793-Washington" "1797-Adams" "1801-Jefferson" ... #> ..$ features: chr [1:9357] "fellow-citizens" "of" "the" "senate" ...
# coercion to a data.frame inaugDfm <- dfm(data_corpus_inaugural[1:5]) as.data.frame(inaugDfm[, 1:10])
#> fellow-citizens of the senate and house representatives : #> 1789-Washington 1 71 116 1 48 2 2 1 #> 1793-Washington 0 11 13 0 2 0 0 1 #> 1797-Adams 3 140 163 1 130 0 2 0 #> 1801-Jefferson 2 104 130 0 81 0 0 1 #> 1805-Jefferson 0 101 143 0 93 0 0 0 #> among vicissitudes #> 1789-Washington 1 1 #> 1793-Washington 0 0 #> 1797-Adams 4 0 #> 1801-Jefferson 1 0 #> 1805-Jefferson 7 0
as.data.frame(inaugDfm[, 1:10], row.names = FALSE)
#> fellow-citizens of the senate and house representatives : among vicissitudes #> 1 1 71 116 1 48 2 2 1 1 1 #> 2 0 11 13 0 2 0 0 1 0 0 #> 3 3 140 163 1 130 0 2 0 4 0 #> 4 2 104 130 0 81 0 0 1 1 0 #> 5 0 101 143 0 93 0 0 0 7 0