“arg”必须是NULL或字符向量。

时间:2021-12-08 17:02:40

Here's a prop.test function:

这是一个道具。测试功能:

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)))

Here is the error:

这是错误:

Error in match.arg(alternative) : 
  'arg' must be NULL or a character vector

Any idea what's wrong?

知道有什么问题吗?

1 个解决方案

#1


4  

According to formals(prop.test) or ?prop.test the fourth argument is called alternative and has to be a character of c("two.sided", "less", "greater"). Your fourth element is conf.level (which is the fifth of prop.test, the order matters). To "ignore" the order of arguments you have to name your arguments (at least the conf.level):

根据形式(prop.test)或?道具。测试第四个参数称为alternative,必须是c的字符(“two”。站”、“少”、“更大的”)。第四个元素是conf.level(这是第五个元素)。测试,订单问题)。要“忽略”论点的顺序,你必须给你的论点起个名字(至少是承认的程度):

prop.test(x, n, p, conf.level=conf.level)

#1


4  

According to formals(prop.test) or ?prop.test the fourth argument is called alternative and has to be a character of c("two.sided", "less", "greater"). Your fourth element is conf.level (which is the fifth of prop.test, the order matters). To "ignore" the order of arguments you have to name your arguments (at least the conf.level):

根据形式(prop.test)或?道具。测试第四个参数称为alternative,必须是c的字符(“two”。站”、“少”、“更大的”)。第四个元素是conf.level(这是第五个元素)。测试,订单问题)。要“忽略”论点的顺序,你必须给你的论点起个名字(至少是承认的程度):

prop.test(x, n, p, conf.level=conf.level)