2
我尝试提示用户输入 “N” 的价值,但我得到一个错误说:在pbinompbinom函数获得错误()
错误(S [I],N,P):
非数值参数 数学函数
如果我直接设定N =任何数量,该功能将正常工作。这里有什么问题?
n = readline("please enter an integer n:")
p = seq(from = 0.05, to = 1,by=0.05)
s = seq(from = 0, to = n)
M <- matrix(0, ncol=length(p), nrow=length(s), dimnames=list(s, p))
for(i in seq_along(s)){
M[i, ] <- pbinom(s[i], n, p)
}
print(round(M,3))
当我尝试数字,我不被允许输入输入,仍然得到错误 – Lin
我不明白。我已经将你的代码复制并粘贴到一个R脚本中,并且它可以正常工作。你在做数字()或as.numeric()吗?它们是有区别的。 – xyz123
n = as.numeric(readline(“请输入整数n:”)) p = seq(from = 0.05,to = 1,by = 0.05) s = seq(from = 0,to = n ) 中号< - 矩阵(0,NcoI位=长度(p),nrow =长度(S),dimnames =列表(S,p)) 为(ⅰ在seq_along(一个或多个)){ M [ I,] < - pbinom(S [I]中,n,p)的 } 打印(圆(M,3)) 这是我有。当我运行代码时,控制台不会要求我输入n – Lin