'arg'必须为NULL或字符向量

Mon*_*lal 2 arguments r function

这是prop.test函数:

baby.prop.test = function (x, n, p, conf.level = 0.95) {
  # ...
  return(prop.test(x,n,p,conf.level))
  #baby.prop.test$statistic
}
# test case
baby.prop = baby.prop.test(72, 100, .7, conf.level=.99)
stopifnot(isTRUE(all.equal(as.numeric(baby.prop$statistic), .43643578)))
stopifnot(isTRUE(all.equal(as.numeric(baby.prop$p.value), .66252058)))
Run Code Online (Sandbox Code Playgroud)

这是错误:

Error in match.arg(alternative) : 
  'arg' must be NULL or a character vector
Run Code Online (Sandbox Code Playgroud)

知道什么是错的吗?

sgi*_*ibb 6

根据formals(prop.test)?prop.test第四个论点被称为alternative并且必须是一个人物c("two.sided", "less", "greater").你的第四个要素是conf.level(这是第五个prop.test,顺序很重要).要"忽略"参数的顺序,你必须为你的参数命名(至少是conf.level):

prop.test(x, n, p, conf.level=conf.level)
Run Code Online (Sandbox Code Playgroud)