找回密码
 注册
查看: 1729|回复: 0

R语言:sparseVector-class()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 17:47:56 | 显示全部楼层 |阅读模式
sparseVector-class(Matrix)
sparseVector-class()所属R语言包:Matrix

                                        Sparse Vector Classes
                                         稀疏向量类

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Sparse Vector Classes: The virtual mother class "sparseVector" has the five actual daughter classes "dsparseVector", "isparseVector", "lsparseVector", "nsparseVector", and "zsparseVector", where we've mainly implemented methods for the d*, l* and n* ones.
稀疏向量类:虚拟母亲类"sparseVector"有实际的五个女儿类"dsparseVector","isparseVector","lsparseVector","nsparseVector","zsparseVector"我们主要实施d*,l*和n*的方法。


插槽----------Slots----------




length: class "numeric" - the length of the sparse vector.  Note that "numeric" can be considerably larger than the maximal "integer",
length:类"numeric" - length稀疏向量。注意"numeric"可以大大超过最大"integer",




i: class "numeric" - the (1-based) indices of the non-zero entries.  Must not be NA and strictly sorted increasingly.
i:类"numeric" - 非零项(1)指数。绝不能NA和越来越严格排序。

Note that "integer" is “part of” "numeric",
注意"integer""numeric"“一部分”,




x: (for all but "nsparseVector"): the non-zero entries.  This is of class "numeric" for class "dsparseVector",  "logical" for class "lsparseVector", etc.
x:(为所有,但"nsparseVector"):非零项。这是类"numeric"类"dsparseVector","logical"为类的"lsparseVector",等。

Note that "nsparseVector"s have no x slot. Further, mainly for ease of method definitions, we've defined the class union (see setClassUnion) of all sparse vector classes which have an x slot, as class "xsparseVector".
请注意,"nsparseVector"S有没有x插槽。此外,主要用于方便的方法定义,我们定义的类工会(见setClassUnion)的所有稀疏向量类,其中有一个x插槽,类"xsparseVector"。


方法----------Methods----------




length signature(x = "sparseVector"): simply extracts
长度signature(x = "sparseVector"):只需提取物




show signature(object = "sparseVector"): The show method for sparse vectors prints “structural” zeroes as "." using the non-exported prSpVector function which allows further customization such as replacing "." by " " (blank).
显示signature(object = "sparseVector"):show稀疏向量的方法,打印的“结构性”零"."使用非出口prSpVector功能,可进一步定制,如更换<X >"."(空)。

Note that options(max.print) will influence how many
请注意,options(max.print)会影响多少




as.vector signature(x = "sparseVector", mode = "character") coerces sparse vectors to &ldquo;regular&rdquo;, i.e., atomic vectors.
as.vectorsignature(x = "sparseVector", mode = "character")胁迫“常规”,即原子向量的稀疏向量。




as ..: see coerce below
如..:看到coerce下面




coerce signature(from = "sparseVector", to = "sparseMatrix"), and
强制signature(from = "sparseVector", to = "sparseMatrix"),




coerce signature(from = "sparseMatrix", to = "sparseVector"), etc: coercions to and from sparse matrices (sparseMatrix) are provided and work analogously as in standard R, i.e., a vector is
强制signature(from = "sparseMatrix", to = "sparseVector")等强制(sparseMatrix)和工作标准的R,即类似于一个向量的稀疏矩阵




dim<- signature(x = "sparseVector", value = "integer") coerces a sparse vector to a sparse Matrix, i.e., an object inheriting from sparseMatrix, of the
昏暗< - signature(x = "sparseVector", value = "integer")胁迫稀疏向量的稀疏矩阵,即从sparseMatrix继承的对象,




head signature(x = "sparseVector"): as with R's (package util) head, head(x,n) (for n >= 1) is equivalent to x[1:n], but here can be much
头signature(x = "sparseVector"):R的(包util)head,head(x,n)(为n >= 1)x[1:n]相当于,但在这里可以多




tail signature(x = "sparseVector"): analogous to
尾巴signature(x = "sparseVector"):类似于




rep signature(x = "sparseVector") repeat x, with the same argument list (x, times, length.out, each,
代表signature(x = "sparseVector")重复x,用相同的参数列表的<code>(X,时间,length.out,每个




Ops signature(e1 = "sparseVector", e2 = "*"): define arithmetic, compare and logic operations, (see
OPSsignature(e1 = "sparseVector", e2 = "*"):定义运算,比较和逻辑运算,(见




Summary signature(x = "sparseVector"): define
摘要signature(x = "sparseVector"):定义




[ signature(x = "atomicVector", i = ...): not only can you subset (aka &ldquo;index into&rdquo;) sparseVectors x[i] using sparseVectors i, but we also support efficient subsetting of traditional vectors x by logical sparse vectors (i.e., i of class "nsparseVector" or
[signature(x = "atomicVector", i = ...):你不仅可以子集(又名“索引”)sparseVectorsx[i]使用sparseVectors i,但我们也支持传统向量的高效子集x逻辑稀疏向量(即i类"nsparseVector"


举例----------Examples----------


getClass("sparseVector")
getClass("dsparseVector")
getClass("xsparseVector")# those with an 'x' slot[那些有一个“x”槽]

sx <- c(0,0,3, 3.2, 0,0,0,-3:1,0,0,2,0,0,5,0,0)
(ss <- as(sx, "sparseVector"))

ix <- as.integer(round(sx))
(is <- as(ix, "sparseVector"))
## an "isparseVector" (!)[#“isparseVector”的(!)]

## rep() works too:[#代表()工作:]
(ri <- rep(is, length.out= 25))

## Using `dim&lt;-`  as in base R :[#昏暗< - 基地&#341;:]
r <- ss
dim(r) &lt;- c(4,5) # becomes a sparse Matrix:[成为一个稀疏矩阵:]
r
## or coercion (as as.matrix() in base R):[#胁迫(如as.matrix(在基地&#341;)):]
as(ss, "Matrix")
stopifnot(all(ss == print(as(ss, "CsparseMatrix"))))

## currently has "non-structural" FALSE -- printing as ":"[#目前有“非结构性”假 - 印刷“:”]
(lis <- is &amp; FALSE)
(nn &lt;- is[is == 0]) # all "structural" FALSE[所有的“结构性”假]

## NA-case[#不适用的情况]
sN <- sx; sN[4] <- NA
(svN <- as(sN, "sparseVector"))

v <- as(c(0,0,3, 3.2, rep(0,9),-3,0,-1, rep(0,20),5,0),
         "sparseVector")
v <- rep(rep(v, 50), 5000)
set.seed(1); v[sample(v@i, 1e6)] <- 0
str(v)




system.time(for(i in 1:4) hv <- head(v, 1e6))
##   user  system elapsed[#用户系统经过]
##  0.033   0.000   0.032[#0.033 0.000 0.032]
system.time(for(i in 1:4) h2 <- v[1:1e6])
##   user  system elapsed[#用户系统经过]
##  1.317   0.000   1.319[#1.317 0.000 1.319]

stopifnot(identical(hv, h2),
          identical(is | FALSE, is != 0),
          validObject(svN), validObject(lis), as.logical(is.na(svN[4])),
          identical(is^2 > 0,        is &amp; TRUE),
          all(!lis), !any(lis), length(nn@i) == 0, !any(nn), all(!nn),
          sum(lis) == 0, !prod(lis), range(lis) == c(0,0))

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-23 03:10 , Processed in 0.022843 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表