format_sparsity: format a sparsity value for printing

Description Usage Arguments Value Examples

View source: R/dfm-print.R

Description

Inputs a dfm sparsity value from sparsity() and formats it for printing in print.dfm().

Usage

1
format_sparsity(x, threshold = 0.01, digits = 3, nsmall = 1)

Arguments

x

input sparsity value, ranging from 0 to 1.0

threshold

value below which the decimal places will be rounded and printed with an inequality

digits

digits input to format()

nsmall

nsmall input to format()

Value

character value for inserting into the dfm print output

Examples

1
2
3
4
5
6
7
8
s <- c(.9, .99, .999, .9999, .99999, 
       .1, .01, .001, .0001, .000001, .0000001, .00000001, .000000000001, 
       sparsity(dfm(data_corpus_inaugural)),
       .12312431242134)
for (i in s) 
    print(paste0(format(i, width = 10),  ":  ", quanteda.core:::format_sparsity(i)))
print(as.dfm(Matrix::rsparsematrix(1000, 1000, density = 0.9999)))
print(as.dfm(Matrix::rsparsematrix(10000, 10000, density = 0.00001)))

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