rapply(base)
rapply()所属R语言包:base
Recursively Apply a Function to a List
递归函数应用到列表
译者:生物统计家园网 机器人LoveR
描述----------Description----------
rapply is a recursive version of lapply.
rapply是lapply的递归版本。
用法----------Usage----------
rapply(object, f, classes = "ANY", deflt = NULL,
how = c("unlist", "replace", "list"), ...)
参数----------Arguments----------
参数:object
A list.
一个列表。
参数:f
A function of a single argument.
一个参数的函数。
参数:classes
A character vector of class names, or "ANY" to match any class.
特征向量的class名,或"ANY"匹配任何类。
参数:deflt
The default result (not used if how = "replace").
如果默认结果(未使用how = "replace")。
参数:how
A character string matching the three possibilities given: see "Details".
三个可能性给一个字符串匹配:见“详细资料”。
参数:...
additional arguments passed to the call to f.
额外的参数传递给调用f。
Details
详情----------Details----------
This function has two basic modes. If how = "replace", each element of the list which is not itself a list and has a class included in classes is replaced by the result of applying f to the element.
这个函数有两个基本模式。如果how = "replace",这本身并不是一个名单,并包括在classes申请f元素的结果取代一类的列表中的每个元素。
If the mode is how = "list" or how = "unlist", the list is copied, all non-list elements which have a class included in classes are replaced by the result of applying f to the element and all others are replaced by deflt. Finally, if how = "unlist", unlist(recursive = TRUE) is called on the result.
如果模式是how = "list"或how = "unlist",列表被复制,所有非列表中的元素,其中包括在classes申请f取代类元素和其他所有被替换deflt。最后,如果how = "unlist",unlist(recursive = TRUE)被称为结果。
The semantics differ in detail from lapply: in particular the arguments are evaluated before calling the C code.
在细节上有所不同的语义从lapply:在特定的参数调用C代码之前进行评估。
值----------Value----------
If how = "unlist", a vector, otherwise a list of similar structure to object.
如果how = "unlist",一个向量,否则类似的结构列表object。
参考文献----------References----------
Programming with Data. Springer.<br> (<code>rapply</code> is only described briefly there.)
参见----------See Also----------
lapply, dendrapply.
lapply,dendrapply。
举例----------Examples----------
X <- list(list(a=pi, b=list(c=1:1)), d="a test")
rapply(X, function(x) x, how="replace")
rapply(X, sqrt, classes="numeric", how="replace")
rapply(X, nchar, classes="character",
deflt = as.integer(NA), how="list")
rapply(X, nchar, classes="character",
deflt = as.integer(NA), how="unlist")
rapply(X, nchar, classes="character", how="unlist")
rapply(X, log, classes="numeric", how="replace", base=2)
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|