我有一个数据框,其中第一列包含数字0,0.01,...,0.99,1。我使用which()函数试图在前三列中查找包含某些数字集的行索引。特别是,这对于第一列中的数字0.35、0.41、0.47、0.57、0.69、0.70、0.82、0.83、0.94和0.95不起作用。我确定它们存在于数据框中,但是which()每次都会返回integer(0)。有人可以帮忙吗?
StateIndex = function(state)
{
state = as.numeric(state)
aux = which(states[,colnames(states)[1]] == state[1])
for (i in 2:3)
{
aux = aux[which(states[aux,colnames(states)[i]] == state[i])]
}
return(aux)
}
states = list()
states[[1]] = seq(0,1,by=1/M) #zeta1 at last action
states[[2]] = 1:(m+1) #i (last observed det. level)
states[[3]] = 0:N #j (time since last action)
states = expand.grid(states)
nstates = dim(states)[1]