R 省略号 - 传递给其他方法或从其他方法传递的进一步参数

标签 r ellipsis

我理解点-点-点的一般含义。当我想创建自己的参数数量未知的函数时,我了解如何使用它。

我不明白它是如何工作的,例如函数 variable.names()。当我执行 ?variable.names 时,写了以下内容:

... further arguments passed to or from other methods.

这到底是什么意思?我不知道我可以在那里传递什么。如何以及在何处使用这些传递的参数。

最佳答案

省略号参数允许将参数传递给下游函数。我们将用一个简单的 R 函数进行说明,如下所示。

testfunc <- function(aFunction,x,...) {
     aFunction(x,...)
}
aVector <- c(1,3,5,NA,7,9,11,32)

# returns NA because aVector contains NA values
testfunc(mean,aVector)

# use ellipsis in testfunc to pass na.rm=TRUE to mean()
testfunc(mean,aVector,na.rm=TRUE)

...和输出:

> testfunc <- function(aFunction,x,...) {
+      aFunction(x,...)
+ }
> aVector <- c(1,3,5,NA,7,9,11,32)
> 
> # returns NA because aVector contains NA values
> testfunc(mean,aVector)
[1] NA
> # use ellipsis in testfunc to pass na.rm=TRUE to mean()
> testfunc(mean,aVector,na.rm=TRUE)
[1] 9.714286

关于R 省略号 - 传递给其他方法或从其他方法传递的进一步参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48480567/

相关文章:

r - 垂直直方图

r - 在本地和远程数据库上使用 dplyr

r - Mac的BiodiversityR软件包的R错误消息

c# - 为什么我收藏的字符串会截断单词?

html - 为什么 CSS 省略号在表格单元格中不起作用?

html - CSS "text-overflow: ellipsis"和垂直居中元素

c++ - cpp : catch exception with ellipsis and see the information

r - group_rows()命令中换行时的缩进 - R markdown 中的 kableExtra 包

r - modalDialog 中的 leafletProxy 未更新

r-markdown - 目录 Rmarkdown 中溢出文本的省略号或缩进