# Tag Info

1

If you are willing to use additional packages, then this could be cleanly handled by performing a rolling apply on your vector. For instance, you could compute if the rolling minimum of your vector with window length 6 equals the rolling maximum with the same window length: library(RcppRoll) as.numeric(roll_min(mydata$ta, 6) == roll_max(mydata$ta, 6)) # [1] ...

1

To my understanding you want a new column qc1 that takes value 1 if the current element matches the previous 5 elements and takes value 0 otherwise. This feels like a great application of run-length encoding. I'll borrow the great example data from @minem: mydata <- data.frame(ta = 1:13) mydata[2:3, 1] <- 1L mydata[6:12, 1] <- 2L mydata\$ta # [1] ...

1

I reduced the example data, for easier viewing # new example data: mydata <- data.frame(ta = 1:13) mydata[2:3, 1] <- 1L mydata[6:12, 1] <- 2L n <- 3 # how many equal values we need require(data.table) setDT(mydata) # convert to data.table mydata mydata[, mathcPrev := fifelse((ta - shift(ta, 1)) == 0L, T, F, F)] mydata[, g := cumsum(!mathcPrev)]...

Only top voted, non community-wiki answers of a minimum length are eligible