The data I have contain three variable with three unique IDs and each has multiple records. See below
ID <- c(rep(1,7), rep(2,6), rep(3,5), rep(4,6))
t <- c(seq(1,7), seq(1,6), seq(1,5), rep(2,6))
y <- c(rep(6,7), rep(1,6), rep(6,5), rep(0.2,6))
z <- c(5,0,0,0,1,0,0,0,0,-1,0,0,0,4,2,NaN,0,1,0,0,1,Inf,Inf, Inf)
dat1 <- data.frame(ID, t, y, z)
For each ID, if the value of z is below 0 (negative), NaN, Inf, or -Inf, I need to exclude that record AND all the records below it.
For this data, the new processed data look like:
ID <- c(rep(1,7), rep(2,2), rep(3,2), rep(4,3))
t <- c(seq(1,7), seq(1,2), seq(1,2), rep(2,3))
y <- c(rep(6,7), rep(1,2), rep(6,2), rep(0.2,3))
z <- c(5,0,0,0,1,0,0,0,0,4,2,0,0,1)
dat2 <- data.frame(ID, t, y, z)