signcount {wordspace} | R 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 |
what |
whether to return the counts of positive, negative and zero elements ( |
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
ifx
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