更新时间:2023-12-03 18:42:16
您非常亲密。应该这样做:
You are very close. This should do it:
row_numbers <- DT[exclude==0 | y==5, .I[{ x <- rep(which(y==5), each=length(idx)) + idx x[x>0 & x<=.N] }], by=grp]$V1 DT[row_numbers]
data.table:在&之前选择n个特定行。在其他行满足条件之后