【问题标题】:Error: Object of type 'closure' is not subesettable?错误:“闭包”类型的对象不是子集?
【发布时间】:2019-02-12 10:32:39
【问题描述】:

我尝试计算矩阵的元素,我正常编写了元素,但是当我运行它时,我收到了以下错误消息:

I[1,1] <- ((1/n)*sum(delta*(((1/alp)-h(x)-(M(x)/(1-W(x))))^2)))

I[1, 1] 中的错误

I[2,2] <- ((1/n)*sum(delta*(((1/b)+log(A(x))-R(x)))^2))

I[2, 2] 中的错误

I[3,3] <- ((1/n)*sum(delta*(((1/d)-(x^gam)-T(x)+((x^gam)))/((((1-exp(-d*x^gam)))*B(x))^2))))

I[3, 3] 中的错误

I[4,4] <- ((1/n)*sum(delta*((1/gam)+log(x)-(d*(x^gam)*log(x))*D(x)-((d*(x^gam)*log(x)*exp(-d*x^gam))/(1-exp(-d*x^gam)))*N(x))^2))

I[4, 4] 中的错误


我不确定为什么,因为我的代码中没有任何更改。

【问题讨论】:

标签: r


【解决方案1】:

I() 是一个禁止解释表达式的函数。尽管如此,它可能会绑定到一个矩阵值,但我的猜测(鉴于缺乏上下文)是您没有将矩阵分配给I,而是分配给其他东西:

> n = 10
> b = 20
> A = function(x) {x+1}
> R = function(x) {x*2}
> delta = 20
> x = 4
> I[1,1] <- ((1/n)*sum(delta*(((1/b)+log(A(x))-R(x)))^2))
Error in I[1, 1] <- ((1/n) * sum(delta * (((1/b) + log(A(x)) - R(x)))^2)) :
  object of type 'closure' is not subsettable
> I
function (x)
{
    structure(x, class = unique(c("AsIs", oldClass(x))))
}
<bytecode: 0x2fdae80>
<environment: namespace:base>
> I = matrix(c(1,2,3,4), nrow=2)
> I[1,1] <- ((1/n)*sum(delta*(((1/b)+log(A(x))-R(x)))^2))
> I
         [,1] [,2]
[1,] 80.40546    3
[2,]  2.00000    4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    • 1970-01-01
    • 2018-02-08
    • 2019-08-09
    • 1970-01-01
    • 2016-03-30
    相关资源
    最近更新 更多