我正在尝试构建一个决策表。例如,在时间3时,我必须在时间t = 1和时间t = 2时采取以前的结果,以便在时间3做出我的决定。决策表将会非常大,所以我正在考虑一种有效的方法来做它通过构建一个函数。例如在时间3:以动态方式扩展条件
rm(list=ls()) # clear memory
names <- c("a","b","c","d","e","f","g","h","i","j","k50","l50","m50","n50","o50")
proba <- c(1,1,1,1,1,1,1,1,1,1,0.5,0.5,0.5,0.5,0.5)
need <- 4
re <- 0.5
w <- 1000000000
# t1
t1 <- as.integer(names %in% (sample(names,need,prob=proba,replace=F)))
# t2
t2 <- rep(t1)
# t3
proba3 <- ifelse(t2==1,proba*re,proba)
t3 <- as.integer(names %in% (sample(names,need,prob=proba3,replace=F)))
现在表将是大直到与proba7 T = 7这需要条件从t = 1到t = 6。在t = 7之后,为了做出决定,总是需要6个以前的结果加上随机部分的概率。换句话说,ifelse必须是动态的,以便以后可以调用它。我一直在尝试像
probF <- function(a){
test <- ifelse(paste0("t",a,sep="")==1,proba*re,proba)
return(test)
}
test <- probF(2)
但有一个错误,因为我只有一个值,而不是一个向量。我知道这看起来复杂
对于由一个人所要求的条件(我知道这是不太好写的):
proba7 <- ifelse(t2==1 & t3==1 & t4==0 & t5==0 & t6==0,proba,
ifelse(t2==1 & t3==0 & t4==0 & t5==1 & t6==1,proba*re,
ifelse(t2==1 & t3==0 & t4==0 & t5==0 & t6==1, w,
ifelse(t2==0 & t3==1 & t4==1 & t5==0 & t6==0,proba,
ifelse(t2==0 & t3==1 & t4==1 & t5==1 & t6==0,0,
ifelse(t2==0 & t3==0 & t4==1 & t5==1 & t6==1,0,
ifelse(t2==0 & t3==0 & t4==1 & t5==1 &t6==0,0,
ifelse(t2==0 & t3==0 & t4==0 & t5==1 & t6==1, proba*re,
ifelse(t2==0 & t3==0 & t4==0 & t5==0 & t6==1,w,proba)))))))))
t7 <- as.integer(names %in% (sample(names,need,prob=proba7,replace=F)))
听起来很糟糕的方法来解决这个问题,因此这个问题似乎是[XY问题](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)。你想做什么 ? – Tensibai
我正在做一个决策表。然而,时间t的决定取决于给定加上随机效应的t-6到t-1的先前决定。但你是对的我的问题不是很清楚我要更新它 – richpiana
@Tensibai我编辑了我的所有问题,以便更清楚,这有帮助吗? – richpiana