Inputs a dfm sparsity value from sparsity()
and formats it for
printing in print.dfm()
.
format_sparsity(x, threshold = 0.01, digits = 3, nsmall = 1)
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 |
|
nsmall |
|
character
value for inserting into the dfm print output
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:::format_sparsity(i)))#> [1] " 0.9: (90.0% sparse)" #> [1] " 0.99: (99.0% sparse)" #> [1] " 0.999: (99.9% sparse)" #> [1] " 0.9999: (99.99% sparse)" #> [1] " 0.99999: (>99.99% sparse)" #> [1] " 0.1: (10.0% sparse)" #> [1] " 0.01: (1.0% sparse)" #> [1] " 0.001: (0.1% sparse)" #> [1] " 1e-04: (0.01% sparse)" #> [1] " 1e-06: (<0.01% sparse)" #> [1] " 1e-07: (<0.01% sparse)" #> [1] " 1e-08: (<0.01% sparse)" #> [1] " 1e-12: (<0.01% sparse)" #> [1] " 0.9176429: (91.8% sparse)" #> [1] " 0.1231243: (12.3% sparse)"#> Document-feature matrix of: 1,000 documents, 1,000 features (<0.01% sparse). #> features #> docs feat1 feat2 feat3 feat4 feat5 feat6 feat7 feat8 feat9 feat10 #> text1 0.093 1.30 0.031 -0.62 0.25 -1.800 0.18 -1.100 0.35 0.47 #> text2 -0.830 -0.86 1.100 0.73 -0.14 -0.032 -0.53 0.080 0.27 0.50 #> text3 -0.180 0.37 -0.530 -0.49 -0.36 -1.300 1.40 -0.780 0.63 0.19 #> text4 -0.770 0.62 2.300 0.19 -1.10 0.630 0.29 0.570 -0.87 0.15 #> text5 -2.800 1.00 0.470 0.19 -0.45 -0.650 1.80 0.033 -1.80 0.66 #> text6 -0.920 0.36 0.930 0.48 -0.24 1.600 1.90 0.130 -0.86 -0.49 #> [ reached max_ndoc ... 994 more documents, reached max_nfeat ... 990 more features ]#> Document-feature matrix of: 10,000 documents, 10,000 features (>99.99% sparse). #> features #> docs feat1 feat2 feat3 feat4 feat5 feat6 feat7 feat8 feat9 feat10 #> text1 0 0 0 0 0 0 0 0 0 0 #> text2 0 0 0 0 0 0 0 0 0 0 #> text3 0 0 0 0 0 0 0 0 0 0 #> text4 0 0 0 0 0 0 0 0 0 0 #> text5 0 0 0 0 0 0 0 0 0 0 #> text6 0 0 0 0 0 0 0 0 0 0 #> [ reached max_ndoc ... 9,994 more documents, reached max_nfeat ... 9,990 more features ]