I want to add ID variable in this data. If receipt_ids are sequenced numbers, then those have same IDs.
CUST_NO_ID receipt_id dollar 12 29
We can use data.table
data.table
library(data.table) setDT(df)[, id := cumsum(c(TRUE, diff(receipt_id)!=1))]
Or use the shift
shift
setDT(df)[, id := cumsum((receipt_id - shift(receipt_id, fill=receipt_id[1]))!=1)]