Learn R Programming

quanteda (version 1.5.2)

format_sparsity: format a sparsity value for printing

Description

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

Usage

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

Run this code
# NOT RUN {
s <- c(.9, .99, .999, .9999, .99999, 
       .1, .01, .001, .0001, .000001, .0000001, .00000001, .000000000001, 
       sparsity(dfm(data_corpus_inaugural)),
       sparsity(dfm(data_corpus_irishbudget2010)),
       .12312431242134)
for (i in s) 
    print(paste0(format(i, width = 10),  ":  ", quanteda:::format_sparsity(i)))
print(as.dfm(Matrix::rsparsematrix(1000, 1000, density = 0.9999)))
print(as.dfm(Matrix::rsparsematrix(10000, 10000, density = 0.00001)))
# }

Run the code above in your browser using DataLab