我希望我正在开发的应用程序自动转到 Excel 表并计算转移概率矩阵。
action<-actions
state<-states
p<-array(0,c(length(state),length(state),length(action)))
colnames(p)=state
rownames(p)=state
# transition probability matrix based on the action that we have choosen
empiricala1<-read.xlsx("www/dynamic model.xlsx",1)
empiricala2<-read.xlsx("www/dynamic model.xlsx",2)
#show(empirical) calculate transition probability from historical data
em1<-as.data.frame(empiricala1)
em2<-as.data.frame(empiricala2)
tab1 <- table(em1)
tab2 <- table(em2)
tab1<-addmargins(prop.table(table(em1$current,em1$nextstate),1),2)
tab2<-addmargins(prop.table(table(em2$current,em2$nextstate),1),2)
transitionprob1<-p[,,1]<-prop.table(table(em1$current,em1$nextstate),1)
transitionprob2<-p[,,2]<-prop.table(table(em2$current,em2$nextstate),2)
print(transitionprob1)
print(transitionprob2)
for(i in 1:length(action)){
p[,,i]<-prop.table(table(em[i]$current,em[i]$nextstate),i)
}
我得到的错误如下:
Error in em[i] : object of type 'closure' is not subsettable
我该如何解决这个问题。