nnzero(Matrix)
nnzero()所属R语言包:Matrix
The Number of Non-Zero Values of a Matrix
矩阵的非零值数
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Returns the number of non-zero values of a numeric-like R object, and in particular an object x inheriting from class Matrix.
返回非零值的一个数字,如R对象的数量,特别是对象x类Matrix继承。
用法----------Usage----------
nnzero(x, na.counted = NA)
参数----------Arguments----------
参数:x
an R object, typically inheriting from class Matrix or numeric.
R对象,通常是从类继承Matrix或numeric。
参数:na.counted
a logical describing how NAs should be counted. There are three possible settings for na.counted:
logical如何NA的应计入。有三种可能的设置为na.counted:
TRUENAs are counted as non-zero (since “they are not zero”).
真NA的计数为非零(因为“他们是不是零”)。
NA(default)the result will be NA if there are NA's in x (since “NA's are not known, i.e., may be zero”).
NA(默认),结果将是NA如果有NA的x(因为“NA的是不知道,也就是说,可能是零”)。
FALSENAs are omitted from x before the non-zero entries are counted. For sparse matrices, you may often want to use na.counted = TRUE.
假NASx前的非零项计算省略。对于稀疏矩阵,您可能经常要使用na.counted = TRUE。
值----------Value----------
the number of non zero entries in x (typically integer).
非零项数(通常是x)integer。
Note that for a symmetric sparse matrix S (i.e., inheriting from class symmetricMatrix), nnzero(S) is typically twice the length(S@x).
注意对称稀疏矩阵S(即,从类继承symmetricMatrix)nnzero(S)是通常的两倍length(S@x)。
方法----------Methods----------
signature(x = "ANY") the default method for non-Matrix class objects, simply counts the number 0s in x, counting NA's depending on
signature(x = "ANY")默认方法非Matrix类的对象,只是计算在0x的计数NA的取决于
signature(x = "denseMatrix") conceptually the same as for traditional matrix objects, care has to be taken
signature(x = "denseMatrix")概念相同,为传统的matrix对象,应采取照顾
signature(x = "pMatrix")</dt> fast simple methods for these
signature(x = "pMatrix")</ DT>这些快速简单的方法
signature(x = "sparseMatrix") typically, the most interesting method, also carefully taking
signature(x = "sparseMatrix")通常情况下,最有趣的方法,也仔细考虑
参见----------See Also----------
The Matrix class also has a length method; typically, length(M) is much larger than nnzero(M) for a sparse matrix M, and the latter is a better indication of the size of M.
也有Matrix类length方法,通常情况下,length(M)比nnzero(M)稀疏矩阵M,后者则是一个更好的大小指示M。
举例----------Examples----------
m <- Matrix(0+1:28, nrow = 4)
m[-3,c(2,4:5,7)] <- m[ 3, 1:4] <- m[1:3, 6] <- 0
(mT <- as(m, "dgTMatrix"))
nnzero(mT)
(S <- crossprod(mT))
nnzero(S)
str(S) # slots are smaller than nnzero()[插槽比nnzero较小()]
stopifnot(nnzero(S) == sum(as.matrix(S) != 0))# failed earlier[未能更早]
data(KNex)
M <- KNex$mm
class(M)
dim(M)
length(M); stopifnot(length(M) == prod(dim(M)))
nnzero(M) # more relevant than length[比长度更相关]
## the above are also visible from[#上面也可见从]
str(M)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|