gpt4 book ai didi

R 错误 : cannot coerce type 'closure' to vector of type 'double'

转载 作者:行者123 更新时间:2023-12-04 10:58:44 25 4
gpt4 key购买 nike

我在我的 R 程序中收到一个错误消息:

Error in as.double(x) : cannot coerce type 'closure' to vector of type 'double'



这是我的代码,我不知道它来自哪里:
norm.pop = rnorm(100000,10,sd = 1)
exp.pop = rexp(100000, rate = 1/10)
true.mean = 10

norm.func = function(n, N, type)
{
if(type == "N")
pop = norm.pop
else if(type =="E")
pop = exp.pop
all.the.probs = sapply(1:N, function(i)
{
the.sample = sample(pop, size = n, replace = TRUE)
x.bar = mean(the.sample)
sd.norm = sd(sample)/sqrt(n)
z.score = 1.96
upper.fence = x.bar + z.score*sd.norm
lower.fence = x.bar - z.score*sd.norm
if((true.mean >= lower.fence) & (true.mean <= upper.fence))
{
return(1)
}
else
{
return (0)
}
})

result = mean(all.the.probs)

return (result)
}

norm.func(10, 10000, "N")

最佳答案

改变:

sd.norm = sd(sample)/sqrt(n)

到:
sd.norm = sd(the.sample)/sqrt(n)

您正在尝试使用函数 sample (一个封闭)作为一个数字(双)

关于R 错误 : cannot coerce type 'closure' to vector of type 'double' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30655967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com