函数中“…”(三点或点对点)的用法

在哪里可以找到有关...in函数用法的文档?例子将是有用的。



森林海
浏览 766回答 3
3回答

白猪掌柜的

用来形容的单词...是“省略号”。知道这一点将使搜索有关构造的信息更加容易。例如,对Google的第一击是该网站上的另一个问题:编写自己的函数时如何使用R的省略号功能?

心有法竹

一个让您入门的小例子。f <- function(x, ...){&nbsp; dots <- list(...)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#1&nbsp; if(length(dots) == 0) return(NULL)&nbsp;&nbsp; cat("The arguments in ... are\n")&nbsp; print(dots)&nbsp; f(...)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #2}f(1,2,3,"a", list("monkey"))函数,f将第一个输入参数以外的所有参数存储在省略号变量中。为了访问其内容,最简单的方法是将其转换为列表(1)。但是,主要用途是将参数传递给子函数,而无需进行转换(2)。

慕无忌1623718

您应该转到“ R语言定义”的第2.1.9节Dot-dot-dot。它与R安装捆绑在一起。help.start()在交互式会话中运行以启动HTML帮助,然后单击“ R语言定义”链接。您也可以从主站点使用PDF或HTML版本。无论如何,...用于匹配函数的未指定形式参数。args(sapply)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;function (X, FUN, ..., simplify = TRUE, USE.NAMES = TRUE)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;NULL&nbsp; &nbsp;sapply(mtcars, mean, trim = .5)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; mpg&nbsp; &nbsp; &nbsp;cyl&nbsp; &nbsp; disp&nbsp; &nbsp; &nbsp; hp&nbsp; &nbsp; drat&nbsp; &nbsp; &nbsp; wt&nbsp; &nbsp; qsec&nbsp; &nbsp; &nbsp; vs&nbsp; &nbsp; &nbsp; am&nbsp; &nbsp; gear&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;19.200&nbsp; &nbsp;6.000 196.300 123.000&nbsp; &nbsp;3.695&nbsp; &nbsp;3.325&nbsp; 17.710&nbsp; &nbsp;0.000&nbsp; &nbsp;0.000&nbsp; &nbsp;4.000&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;carb&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; 2.000&nbsp;如您所见,trim = .5尽管没有将其指定为sapply函数的形式参数,但我还是通过了。(请注意,此示例是微不足道的,可以sapply(mtcars, median)用来实现相同的结果)
打开App,查看更多内容
随时随地看视频慕课网APP