0

I'm trying to create a data table and do some calculations about it for my assignment. However, when I create and manipulate data, for some reason filtering does not work. For instance if I filter column 's' for the value 0.7, no solution. For the value 0.9, it works as it should. It's weird.

Thanks for any help.

    library(data.table)

    p<-as.data.table(cbind(0:6, c(0,0.15,0.33,0.37,0.40,0.42,0.43)))
    states<-seq(from=0, to=30,by=0.1)
    actions<-seq(from=0,to=6)
    actions<-as.data.table(actions)
    actions[,hunt_share:=numeric()]
    for(i in 1:7)
    {
      if(i==1)
        actions[i]$hunt_share<-0
      else
        actions[i]$hunt_share<-floor(164/(i-1)*10)/10
    }

    u_star<-data.table(t=integer(),s=numeric(),a=integer(),value=numeric())
    r<-data.table(t=integer(),s_bar=numeric(),s=numeric(),a=integer(),value=numeric())
    trans_prob<-data.table(t=integer(),s_bar=numeric(),s=numeric(),a=integer(),value=numeric())
    str(trans_prob)
    ####### transitional probabilities
    horizon<-5
    for(time in 1:horizon)
    {
      for(i in states)
      {
        for(a in actions$actions)
        {
          if((a==0))
          {
            tmp<-data.table(t(c(time,max(i-6,0),i,a,1)))
            colnames(tmp)<-colnames(trans_prob)
            trans_prob<-rbind(trans_prob,tmp,fill=T)
          }

          if((a>0)&(i>=0.5))
          {
            tmp<-data.table(t(c(time,min(30,i+actions[actions==a]$hunt_share-6.5),i,a,p[V1==a]$V2)))
            colnames(tmp)<-colnames(trans_prob)
            trans_prob<-rbind(trans_prob,tmp,fill=T)

            tmp<-data.table(t(c(time,max(i-6.5,0),i,a,1-p[V1==a]$V2)))
            colnames(tmp)<-colnames(trans_prob)
            trans_prob<-rbind(trans_prob,tmp,fill=T)
          }
        }

      }
      print(time)
    }
    ####### transitional probabilities

    ##Bug?
    trans_prob[s==0.9]
    trans_prob[s==0.7]
    ##Bug?
rawr
  • 20,481
  • 4
  • 44
  • 78
volkan g
  • 186
  • 10

0 Answers0