signcount: Efficiently Count Positive, Negative and Zero Values...

signcountR Documentation

Efficiently Count Positive, Negative and Zero Values (wordspace)

Description

This function counts the number of positive, negative and zero elements in a numeric vector or matrix, including some types of dense and sparse representations in the Matrix package.

It can be used to test for non-negativity and compute nonzero counts efficiently, without any memory overhead.

Usage


signcount(x, what = c("counts", "nonneg", "nnzero"))

Arguments

x

a numeric vector or array, or a numeric Matrix (supported formats are dgeMatrix, dgCMatrix and dgRMatrix)

what

whether to return the counts of positive, negative and zero elements (counts), the number of nonzero elements (nnzero), or to test for non-negativity (nonneg); see ‘Value’ below

Details

x must not contain any undefined values; signcount does not check whether this is actually the case.

Value

what="counts"

A labelled numeric vector of length 3 with the counts of positive (pos), zero (zero) and negative (neg) values.

what="nonneg"

A single logical value: TRUE if x is non-negative, FALSE otherwise.

what="nonzero"

A single numeric value, the total number of nonzero elements in x.

Author(s)

Stephanie Evert (https://purl.org/stephanie.evert)

Examples

signcount(DSM_TermTermMatrix)     # dense matrix
signcount(DSM_TermContextMatrix)  # sparse dgCMatrix
signcount(DSM_TermContextMatrix, "nonneg") # confirm that it is non-negative

wordspace documentation built on Aug. 23, 2022, 1:06 a.m.