Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't find documentation for R function row_sums and col_sums
    primarykey
    data
    text
    <p>I am trying to resolve my own question regarding changing the tf-idf weighting function in the <code>tm</code> package: <a href="https://stackoverflow.com/questions/15045313/changing-tf-idf-weight-function-weight-not-by-occurrences-of-term-but-by-numbe">https://stackoverflow.com/questions/15045313/changing-tf-idf-weight-function-weight-not-by-occurrences-of-term-but-by-numbe</a></p> <p>In doing so, I'm looking at the <code>weightTfIdf</code> function which includes the following code on <code>m</code>, a TermDocumentMatrix.</p> <pre><code>cs &lt;- col_sums(m) </code></pre> <p>and</p> <pre><code>rs &lt;- row_sums(m) </code></pre> <p>But I can't find any documentation for the functions <code>row_sums</code> or <code>col_sums</code>; and when I try to write my own weighting function using them, I get an error: <code>Error in weighting(x) : could not find function "col_sums"</code></p> <p>Where are these functions defined? </p> <p>I've pasted the complete function information from <code>R</code> below:</p> <pre><code>function (m, normalize = TRUE) { isDTM &lt;- inherits(m, "DocumentTermMatrix") if (isDTM) m &lt;- t(m) if (normalize) { cs &lt;- col_sums(m) if (any(cs == 0)) warning("empty document(s): ", paste(Docs(m)[cs == 0], collapse = " ")) names(cs) &lt;- seq_len(nDocs(m)) m$v &lt;- m$v/cs[m$j] } rs &lt;- row_sums(m &gt; 0) if (any(rs == 0)) warning("unreferenced term(s): ", paste(Terms(m)[rs == 0], collapse = " ")) lnrs &lt;- log2(nDocs(m)/rs) lnrs[!is.finite(lnrs)] &lt;- 0 m &lt;- m * lnrs attr(m, "Weighting") &lt;- c(sprintf("%s%s", "term frequency - inverse document frequency", if (normalize) " (normalized)" else ""), "tf-idf") if (isDTM) t(m) else m } &lt;environment: namespace:tm&gt; attr(,"class") [1] "WeightFunction" "function" attr(,"Name") [1] "term frequency - inverse document frequency" attr(,"Acronym") [1] "tf-idf" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload