如何檢查函式在 R 中期望的最小引數數量?
藉助語法 length(formals(“function_name”)) 可以找出函式在 R 中使用時期望的最小引數數量。例如,要找出 dplyr 程式包 mutate 函式期望的引數數量,可以使用命令 length(formals(mutate)) 來計算,但我們需要確保程式包已載入。
例項
library(ggplot2) length(formals(ggplot))
輸出
[1] 4 length(formals(boxplot)) [1] 2 length(formals(qnorm)) [1] 5 length(formals(rnorm)) [1] 3 length(formals(rpois)) [1] 2 length(formals(runif)) [1] 3 length(formals(punif)) [1] 5 length(formals(plot)) [1] 3 length(formals(pbinom)) [1] 5 length(formals(qbinom)) [1] 5 length(formals(hist)) [1] 2 length(formals(data)) [1] 7 length(formals(matrix)) [1] 5 length(formals(list)) [1] 0 length(formals(data.frame)) [1] 6 length(formals(paste)) [1] 4 length(formals(gsub)) [1] 7 length(formals(factor)) [1] 6 length(formals(cut)) [1] 2 length(formals(t.test)) [1] 2 length(formals(lm)) [1] 14 length(formals(glm)) [1] 18 length(formals(prop.test)) [1] 6 length(formals(pairwise.t.test)) [1] 7 length(formals(aov)) [1] 6 length(formals(dunif)) [1] 4 length(formals(dpois)) [1] 3 length(formals(dnorm)) [1] 4 length(formals(cbind)) [1] 2 length(formals(rbind)) [1] 2 length(formals(cor)) [1] 4 length(formals(cor.test)) [1] 2 length(formals(mean)) [1] 2 length(formals(sum)) [1] 0 length(formals(median)) [1] 3 length(formals(quantile)) [1] 2 length(formals(rank)) [1] 3 length(formals(var)) [1] 4 length(formals(sd)) [1] 2 length(formals(round)) [1] 0
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP