apply(spam)
apply()所属R语言包:spam
Apply Functions Over Sparse Matrix Margins
超过稀疏矩阵空间应用功能
译者:生物统计家园网 机器人LoveR
描述----------Description----------
Returns a vector or array or list of values obtained by applying a
返回向量或数组的值列表应用
用法----------Usage----------
参数----------Arguments----------
参数:X
the spam matrix to be used.
spam要使用的矩阵。
参数:MARGIN
a vector giving the subscripts which the function will be applied over. 1 indicates rows, 2 indicates columns, NULL or c(1,2) indicates rows and columns.
给下标,该函数将被施加在一个向量。 1表示行,2表示列,NULL或c(1,2)表示的行和列。
参数:FUN
the function to be applied.
该函数被应用。
参数:...
optional arguments to FUN.
可选参数到FUN。
Details
详细信息----------Details----------
This is a handy wrapper to apply a function to the (nonzero) elements of a sparse matrix. For example, it is possible to apply a covariance matrix to a distance matrix obtained by nearest.dist, see Examples.<br>
这是一个方便的包装应用功能的稀疏矩阵的非零元素。例如,它可以通过以下方式获得nearest.dist到距离矩阵申请的协方差矩阵,请参见实施例。<br>物理化学学报
A call to apply only coerces the sparse matrix to a regular one.<br>
的调用apply只有稀疏矩阵强制定期。<BR>
The basic principle is applying the function to @entries, or to the extracted columns or rows ([,i,drop=F] or [i,,drop=F]). It is important to note that an empty column contains at least one zero value and may lead to non intuitive results.<br>
其基本原理是应用的功能@entries,或提取的列或行([,i,drop=F]或[i,,drop=F])。重要的是要注意,空柱中至少包含一个零值,并可能导致非直观的效果。<br>物理化学学报
This function may evolve over the next few releases.
此功能可能会随着未来几个版本。
值----------Value----------
Similar as a call to apply with a regular matrix. The most important cases are as follows. The result is a vector (MARGIN is length 1 and FUN is scalar) or a matrix (MARGIN is length 1 and FUN returns fixed length vectors, or MARGIN is length 2 and FUN is
调用apply:一个普通的矩阵相似。最重要的情况如下。的结果是一个向量(MARGIN是长度为1和FUN是标量)或矩阵(MARGIN是长度为1和FUN返回固定长度的向量,或<X >是长度为2和MARGIN
(作者)----------Author(s)----------
Reinhard Furrer
参见----------See Also----------
base:apply for more details on Value.
base:apply价值的详细信息。
实例----------Examples----------
S <- as.spam(dist(1:5))
S <- apply.spam(S/2, NULL, exp)
# instead of [而不是]
# S@entries <- exp( S@entries/2) [小号@项 - (S @项/ 2)]
# Technical detail, a null matrix consists[技术细节,一个空矩阵由]
# of one zero element.[一个零元素。]
apply.spam(S,c(1,2),pmax)
apply.spam(S,1,range)
# A similar example as for the base apply.[一个类似的例子的基础。]
# However, no dimnames else we would get warnings. [然而,没有dimnames,否则我们会得到警告。]
x <- as.spam(cbind(x1 = 3, x2 = c(0,0,0, 5:2)))
apply.spam(x, 2, mean, trim = .2)
col.sums <- apply.spam(x, 2, sum)
row.sums <- apply.spam(x, 1, sum)
rbind(cbind(x, row.sums), c(col.sums, sum(col.sums)))
apply.spam(x, 2, is.vector)
# Sort the columns of a matrix[矩阵的列进行排序]
# Notice that the result is a list due to the different[请注意,由于使用了不同的结果是一个列表]
# lengths induced by the nonzero elements[长度诱导的非零元素]
apply.spam(x, 2, sort)
# Function with extra args:[ARGS额外的功能:]
cave <- function(x, c1, c2) c(mean(x[c1]), mean(x[c2]))
apply(x,1, cave, c1=1, c2=c(1,2))
ma <- spam(c(1:4, 0, 0,0, 6), nrow = 2)
ma
apply.spam(ma, 1, table) #--> a list of length 2[ - >长度为2的列表]
apply.spam(ma, 1, stats::quantile)# 5 x n matrix with rownames[5×n矩阵与rownames]
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|